qortal-ui/qortal-ui-crypto/api/transactions/PaymentTransaction.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-12-25 14:39:47 +01:00
'use strict';
import TransactionBase from './TransactionBase.js'
import Base58 from '../deps/Base58.js'
import { store } from '../../api.js'
export default class PaymentTransaction extends TransactionBase {
constructor() {
super()
this.type = 2
this.tests.push(
() => {
if (!(this._amount >= 0)) {
return 'Invalid amount ' + this._amount / store.getState().config.coin.decimals
}
return true
},
() => {
if (!(this._recipient instanceof Uint8Array && this._recipient.length == 25)) {
return 'Invalid recipient ' + Base58.encode(this._recipient)
}
return true
}
)
}
set recipient(recipient) { // Always Base58 encoded. Accepts Uint8Array or Base58 string.
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
}
2022-04-16 17:14:24 +02:00
set dialogto(dialogto) {
this._dialogto = dialogto
}
set dialogamount(dialogamount) {
this._dialogamount = dialogamount
}
2022-09-02 01:45:47 +03:00
2021-12-25 14:39:47 +01:00
set amount(amount) {
2022-08-29 20:08:50 +02:00
this._amount = Math.round(amount * store.getState().config.coin.decimals)
2021-12-25 14:39:47 +01:00
this._amountBytes = this.constructor.utils.int64ToBytes(this._amount)
}
2022-04-16 17:14:24 +02:00
2021-12-25 14:39:47 +01:00
get params() {
const params = super.params
params.push(
this._recipient,
this._amountBytes,
this._feeBytes
)
return params
}
render(html) {
const conf = store.getState().config
return html`
<table>
<tr>
2022-09-02 01:45:47 +03:00
<th>${this._dialogto}:</th>
</tr>
<tr>
<td>${this.dialogAddress} ${' '}-</td>
<td>${Base58.encode(this._recipient)}</td>
</tr>
${this.recipientName ? html`
<tr>
<td>${this.dialogName} ${' '}-</td>
<td>${this.recipientName}</td>
2021-12-25 14:39:47 +01:00
</tr>
2022-09-02 01:45:47 +03:00
` : ''}
2021-12-25 14:39:47 +01:00
<tr>
2022-04-16 17:14:24 +02:00
<th>${this._dialogamount}</th>
2021-12-25 14:39:47 +01:00
<td>${this._amount / conf.coin.decimals} ${conf.coin.symbol}</td>
</tr>
</table>
`
}
}