Set default value for minimum token to 1

This impact both poll creation and responding to poll.
This commit is contained in:
Franck 2021-12-21 14:52:24 +11:00
parent 772d15be02
commit 857b3438a4
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 10 additions and 4 deletions

View File

@ -11,6 +11,8 @@ import { WakuMessaging } from './WakuMessaging'
import { Web3Provider } from '@ethersproject/providers'
import { WakuMessagesSetup } from '../types/WakuMessagesSetup'
const MinTokenDefaultValue = BigNumber.from(1)
export enum MESSAGE_SENDING_RESULT {
ok = 0,
notEnoughToken = 1,
@ -72,7 +74,8 @@ export class WakuPolling extends WakuMessaging {
const signer = this.provider.getSigner()
const address = await signer.getAddress()
await this.updateBalances([address])
if (this.addressesBalances[address] && this.addressesBalances[address]?.gt(minToken ?? BigNumber.from(0))) {
if (this.addressesBalances[address] && this.addressesBalances[address]?.gt(minToken ?? MinTokenDefaultValue)) {
const pollInit = await PollInitMsg.create(signer, question, answers, pollType, this.chainId, minToken, endTime)
if (pollInit) {
await this.sendWakuMessage(this.wakuMessages['pollInit'], pollInit)
@ -91,7 +94,10 @@ export class WakuPolling extends WakuMessaging {
const poll = this.wakuMessages['pollInit'].arr.find((poll: PollInitMsg): poll is PollInitMsg => poll.id === pollId)
if (poll) {
await this.updateBalances([address])
if (this.addressesBalances[address] && this.addressesBalances[address]?.gt(poll.minToken ?? BigNumber.from(0))) {
if (
this.addressesBalances[address] &&
this.addressesBalances[address]?.gt(poll.minToken ?? MinTokenDefaultValue)
) {
const pollVote = await TimedPollVoteMsg.create(signer, pollId, selectedAnswer, this.chainId, tokenAmount)
if (pollVote) {
await this.sendWakuMessage(this.wakuMessages['pollVote'], pollVote)
@ -112,7 +118,7 @@ export class WakuPolling extends WakuMessaging {
.map((poll: PollInitMsg) => {
if (
this.addressesBalances[poll.owner] &&
this.addressesBalances[poll.owner]?.gt(poll.minToken ?? BigNumber.from(0))
this.addressesBalances[poll.owner]?.gt(poll.minToken ?? MinTokenDefaultValue)
) {
return new DetailedTimedPoll(
poll,
@ -121,7 +127,7 @@ export class WakuPolling extends WakuMessaging {
(vote: TimedPollVoteMsg) =>
vote.pollId === poll.id &&
this.addressesBalances[poll.owner] &&
this.addressesBalances[vote.voter]?.gt(poll.minToken ?? BigNumber.from(0))
this.addressesBalances[vote.voter]?.gt(poll.minToken ?? MinTokenDefaultValue)
)
.filter((e): e is TimedPollVoteMsg => !!e)
)