Dynamic fee
This commit is contained in:
parent
d1facdd91a
commit
ea40ab54a5
@ -9,32 +9,35 @@ import { use, get, translate, translateUnsafeHTML, registerTranslateConfig } fro
|
|||||||
const parentEpml = new Epml({ type: "WINDOW", source: window.parent });
|
const parentEpml = new Epml({ type: "WINDOW", source: window.parent });
|
||||||
|
|
||||||
export class TipUser extends LitElement {
|
export class TipUser extends LitElement {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
userName: { type: String },
|
userName: { type: String },
|
||||||
walletBalance: { type: Number },
|
walletBalance: { type: Number },
|
||||||
sendMoneyLoading: { type: Boolean },
|
sendMoneyLoading: { type: Boolean },
|
||||||
closeTipUser: { type: Boolean },
|
closeTipUser: { type: Boolean },
|
||||||
btnDisable: { type: Boolean },
|
btnDisable: { type: Boolean },
|
||||||
errorMessage: { type: String },
|
errorMessage: { type: String },
|
||||||
successMessage: { type: String },
|
successMessage: { type: String },
|
||||||
setOpenTipUser: { attribute: false },
|
setOpenTipUser: { attribute: false },
|
||||||
|
qortPaymentFee: { type: Number }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.sendMoneyLoading = false
|
this.sendMoneyLoading = false
|
||||||
this.btnDisable = false
|
this.btnDisable = false
|
||||||
this.errorMessage = ""
|
this.errorMessage = ""
|
||||||
this.successMessage = ""
|
this.successMessage = ""
|
||||||
this.myAddress = window.parent.reduxStore.getState().app.selectedAddress
|
this.myAddress = window.parent.reduxStore.getState().app.selectedAddress
|
||||||
|
this.qortPaymentFee = 0.01
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = [tipUserStyles]
|
static styles = [tipUserStyles]
|
||||||
|
|
||||||
async firstUpdated() {
|
async firstUpdated() {
|
||||||
await this.fetchWalletDetails()
|
await this.fetchWalletDetails()
|
||||||
|
this.paymentFee()
|
||||||
}
|
}
|
||||||
|
|
||||||
updated(changedProperties) {
|
updated(changedProperties) {
|
||||||
@ -48,12 +51,34 @@ export class TipUser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getLastRef() {
|
async getLastRef() {
|
||||||
let myRef = await parentEpml.request("apiCall", {
|
let myRef = await parentEpml.request("apiCall", {
|
||||||
type: "api",
|
type: "api",
|
||||||
url: `/addresses/lastreference/${this.myAddress.address}`,
|
url: `/addresses/lastreference/${this.myAddress.address}`,
|
||||||
})
|
})
|
||||||
return myRef
|
return myRef
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSendQortFee() {
|
||||||
|
let sendFee = await parentEpml.request('apiCall', {
|
||||||
|
type: "api",
|
||||||
|
url: `/transactions/unitfee?txType=PAYMENT`
|
||||||
|
})
|
||||||
|
return (Number(sendFee) / 1e8).toFixed(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
async paymentFee() {
|
||||||
|
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||||
|
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
|
||||||
|
const url = `${nodeUrl}/transactions/unitfee?txType=PAYMENT`
|
||||||
|
await fetch(url).then((response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json()
|
||||||
|
}
|
||||||
|
return Promise.reject(response)
|
||||||
|
}).then((json) => {
|
||||||
|
this.qortPaymentFee = (Number(json) / 1e8).toFixed(8)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
renderSuccessText() {
|
renderSuccessText() {
|
||||||
return html`${translate("chatpage.cchange55")}`
|
return html`${translate("chatpage.cchange55")}`
|
||||||
@ -89,7 +114,7 @@ export class TipUser extends LitElement {
|
|||||||
this.sendMoneyLoading = true
|
this.sendMoneyLoading = true
|
||||||
this.btnDisable = true
|
this.btnDisable = true
|
||||||
|
|
||||||
if (parseFloat(amount) + parseFloat(0.001) > parseFloat(this.walletBalance)) {
|
if (parseFloat(amount) + parseFloat(0.011) > parseFloat(this.walletBalance)) {
|
||||||
this.sendMoneyLoading = false
|
this.sendMoneyLoading = false
|
||||||
this.btnDisable = false
|
this.btnDisable = false
|
||||||
let snack1string = get("chatpage.cchange51")
|
let snack1string = get("chatpage.cchange51")
|
||||||
@ -125,7 +150,7 @@ export class TipUser extends LitElement {
|
|||||||
} else {
|
} else {
|
||||||
myRes = myNameRes
|
myRes = myNameRes
|
||||||
}
|
}
|
||||||
return myRes;
|
return myRes
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateAddress = async (receiverAddress) => {
|
const validateAddress = async (receiverAddress) => {
|
||||||
@ -135,6 +160,7 @@ export class TipUser extends LitElement {
|
|||||||
|
|
||||||
const validateReceiver = async (recipient) => {
|
const validateReceiver = async (recipient) => {
|
||||||
let lastRef = await this.getLastRef()
|
let lastRef = await this.getLastRef()
|
||||||
|
let theFee = await this.getSendQortFee()
|
||||||
let isAddress
|
let isAddress
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -144,13 +170,13 @@ export class TipUser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isAddress) {
|
if (isAddress) {
|
||||||
let myTransaction = await makeTransactionRequest(recipient, lastRef)
|
let myTransaction = await makeTransactionRequest(recipient, lastRef, theFee)
|
||||||
getTxnRequestResponse(myTransaction)
|
getTxnRequestResponse(myTransaction)
|
||||||
} else {
|
} else {
|
||||||
let myNameRes = await validateName(recipient)
|
let myNameRes = await validateName(recipient)
|
||||||
if (myNameRes !== false) {
|
if (myNameRes !== false) {
|
||||||
let myNameAddress = myNameRes.owner
|
let myNameAddress = myNameRes.owner
|
||||||
let myTransaction = await makeTransactionRequest(myNameAddress, lastRef)
|
let myTransaction = await makeTransactionRequest(myNameAddress, lastRef, theFee)
|
||||||
getTxnRequestResponse(myTransaction)
|
getTxnRequestResponse(myTransaction)
|
||||||
} else {
|
} else {
|
||||||
console.error(this.renderReceiverText())
|
console.error(this.renderReceiverText())
|
||||||
@ -178,9 +204,10 @@ export class TipUser extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeTransactionRequest = async (receiver, lastRef) => {
|
const makeTransactionRequest = async (receiver, lastRef, theFee) => {
|
||||||
let myReceiver = receiver
|
let myReceiver = receiver
|
||||||
let mylastRef = lastRef
|
let mylastRef = lastRef
|
||||||
|
let myFee = theFee
|
||||||
let dialogamount = get("transactions.amount")
|
let dialogamount = get("transactions.amount")
|
||||||
let dialogAddress = get("login.address")
|
let dialogAddress = get("login.address")
|
||||||
let dialogName = get("login.name")
|
let dialogName = get("login.name")
|
||||||
@ -194,7 +221,7 @@ export class TipUser extends LitElement {
|
|||||||
recipientName: recipientName,
|
recipientName: recipientName,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
lastReference: mylastRef,
|
lastReference: mylastRef,
|
||||||
fee: 0.001,
|
fee: myFee,
|
||||||
dialogamount: dialogamount,
|
dialogamount: dialogamount,
|
||||||
dialogto: dialogto,
|
dialogto: dialogto,
|
||||||
dialogAddress,
|
dialogAddress,
|
||||||
@ -239,7 +266,7 @@ export class TipUser extends LitElement {
|
|||||||
<div class="tip-user-body">
|
<div class="tip-user-body">
|
||||||
<p class="tip-available">${translate("chatpage.cchange47")}: ${this.walletBalance} QORT</p>
|
<p class="tip-available">${translate("chatpage.cchange47")}: ${this.walletBalance} QORT</p>
|
||||||
<input id="amountInput" class="tip-input" type="number" placeholder="${translate("chatpage.cchange46")}" />
|
<input id="amountInput" class="tip-input" type="number" placeholder="${translate("chatpage.cchange46")}" />
|
||||||
<p class="tip-available">${translate("chatpage.cchange49")}: 0.001 QORT</p>
|
<p class="tip-available">${translate("chatpage.cchange49")}: ${this.qortPaymentFee} QORT</p>
|
||||||
${this.sendMoneyLoading ?
|
${this.sendMoneyLoading ?
|
||||||
html`
|
html`
|
||||||
<paper-progress indeterminate style="width: 100%; margin: 4px;">
|
<paper-progress indeterminate style="width: 100%; margin: 4px;">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user