2024-05-08 13:16:23 +02:00
|
|
|
import TransactionBase from '../TransactionBase'
|
|
|
|
import {QORT_DECIMALS} from '../../constants'
|
2023-09-19 00:37:50 -05:00
|
|
|
|
|
|
|
export default class CreatePollTransaction extends TransactionBase {
|
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
this.type = 8
|
|
|
|
this._options = []
|
|
|
|
}
|
|
|
|
|
|
|
|
render(html) {
|
|
|
|
return html`
|
|
|
|
${this._votedialog3}
|
|
|
|
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
|
|
|
<span style="color: #000;">${this._rPollName}</span>
|
|
|
|
</div>
|
|
|
|
${this._votedialog4}
|
|
|
|
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
|
|
|
<span style="color: #000;">${this._rPollDesc}</span>
|
|
|
|
</div>
|
|
|
|
${this._votedialog5}
|
|
|
|
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
|
|
|
<span style="color: #000;">${this._pollOptions.join(', ')}</span>
|
|
|
|
</div>
|
|
|
|
${this._votedialog6}
|
2023-09-19 10:56:11 -05:00
|
|
|
<div style="margin-top: 10px; font-weight: bold">
|
2024-05-08 13:16:23 +02:00
|
|
|
${this._feeDialog}: ${this._feeDisplay}
|
2023-09-19 10:56:11 -05:00
|
|
|
</div>
|
2023-09-19 00:37:50 -05:00
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
addOption(option) {
|
2024-05-08 13:16:23 +02:00
|
|
|
const optionBytes = this.constructor.utils.stringtoUTF8Array(option)
|
|
|
|
const optionLength = this.constructor.utils.int32ToBytes(optionBytes.length)
|
|
|
|
this._options.push({ length: optionLength, bytes: optionBytes })
|
2023-09-19 00:37:50 -05:00
|
|
|
}
|
|
|
|
|
2023-09-19 10:56:11 -05:00
|
|
|
set feeDialog(feeDialog){
|
|
|
|
this._feeDialog = feeDialog
|
|
|
|
}
|
|
|
|
|
2023-09-19 00:37:50 -05:00
|
|
|
set votedialog3(votedialog3) {
|
|
|
|
this._votedialog3 = votedialog3
|
|
|
|
}
|
|
|
|
|
|
|
|
set votedialog4(votedialog4) {
|
|
|
|
this._votedialog4 = votedialog4
|
|
|
|
}
|
2023-11-09 17:31:27 +01:00
|
|
|
|
2023-09-19 00:37:50 -05:00
|
|
|
set votedialog5(votedialog5) {
|
|
|
|
this._votedialog5 = votedialog5
|
|
|
|
}
|
2023-11-09 17:31:27 +01:00
|
|
|
|
2023-09-19 00:37:50 -05:00
|
|
|
set votedialog6(votedialog6) {
|
|
|
|
this._votedialog6 = votedialog6
|
|
|
|
}
|
|
|
|
|
|
|
|
set fee(fee) {
|
2023-09-19 10:56:11 -05:00
|
|
|
this._feeDisplay = fee
|
2023-09-19 00:37:50 -05:00
|
|
|
this._fee = fee * QORT_DECIMALS
|
|
|
|
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
|
|
|
}
|
|
|
|
|
|
|
|
set ownerAddress(ownerAddress) {
|
|
|
|
this._ownerAddress = ownerAddress instanceof Uint8Array ? ownerAddress : this.constructor.Base58.decode(ownerAddress)
|
|
|
|
}
|
|
|
|
|
|
|
|
set rPollName(rPollName) {
|
|
|
|
this._rPollName = rPollName
|
|
|
|
this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(this._rPollName)
|
2024-05-08 13:16:23 +02:00
|
|
|
this._rPollNameLength = this.constructor.utils.int32ToBytes(this._rPollNameBytes.length)
|
2023-09-19 00:37:50 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set rPollDesc(rPollDesc) {
|
|
|
|
this._rPollDesc = rPollDesc
|
|
|
|
this._rPollDescBytes = this.constructor.utils.stringtoUTF8Array(this._rPollDesc.toLocaleLowerCase())
|
|
|
|
this._rPollDescLength = this.constructor.utils.int32ToBytes(this._rPollDescBytes.length)
|
|
|
|
}
|
|
|
|
|
|
|
|
set rOptions(rOptions) {
|
2024-05-08 13:16:23 +02:00
|
|
|
const optionsArray = rOptions[0].split(', ').map(opt => opt.trim())
|
2023-11-05 14:30:07 +01:00
|
|
|
this._pollOptions = optionsArray
|
2024-05-08 13:16:23 +02:00
|
|
|
|
2023-09-19 00:37:50 -05:00
|
|
|
for (let i = 0; i < optionsArray.length; i++) {
|
2024-05-08 13:16:23 +02:00
|
|
|
this.addOption(optionsArray[i])
|
2023-09-19 00:37:50 -05:00
|
|
|
}
|
2023-11-05 14:30:07 +01:00
|
|
|
|
2024-05-08 13:16:23 +02:00
|
|
|
this._rNumberOfOptionsBytes = this.constructor.utils.int32ToBytes(optionsArray.length)
|
2023-09-19 00:37:50 -05:00
|
|
|
}
|
2023-11-05 14:30:07 +01:00
|
|
|
|
2023-09-19 00:37:50 -05:00
|
|
|
|
|
|
|
get params() {
|
|
|
|
const params = super.params
|
|
|
|
params.push(
|
|
|
|
this._ownerAddress,
|
|
|
|
this._rPollNameLength,
|
|
|
|
this._rPollNameBytes,
|
|
|
|
this._rPollDescLength,
|
|
|
|
this._rPollDescBytes,
|
|
|
|
this._rNumberOfOptionsBytes
|
|
|
|
)
|
2024-05-08 13:16:23 +02:00
|
|
|
|
2023-09-19 00:37:50 -05:00
|
|
|
// Push the dynamic options
|
|
|
|
for (let i = 0; i < this._options.length; i++) {
|
2024-05-08 13:16:23 +02:00
|
|
|
params.push(this._options[i].length, this._options[i].bytes)
|
2023-09-19 00:37:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
params.push(this._feeBytes);
|
|
|
|
|
|
|
|
return params
|
|
|
|
}
|
2023-11-05 14:30:07 +01:00
|
|
|
}
|