Set default value for minimum token to 1
This impact both poll creation and responding to poll.
This commit is contained in:
parent
772d15be02
commit
857b3438a4
|
@ -11,6 +11,8 @@ import { WakuMessaging } from './WakuMessaging'
|
||||||
import { Web3Provider } from '@ethersproject/providers'
|
import { Web3Provider } from '@ethersproject/providers'
|
||||||
import { WakuMessagesSetup } from '../types/WakuMessagesSetup'
|
import { WakuMessagesSetup } from '../types/WakuMessagesSetup'
|
||||||
|
|
||||||
|
const MinTokenDefaultValue = BigNumber.from(1)
|
||||||
|
|
||||||
export enum MESSAGE_SENDING_RESULT {
|
export enum MESSAGE_SENDING_RESULT {
|
||||||
ok = 0,
|
ok = 0,
|
||||||
notEnoughToken = 1,
|
notEnoughToken = 1,
|
||||||
|
@ -72,7 +74,8 @@ export class WakuPolling extends WakuMessaging {
|
||||||
const signer = this.provider.getSigner()
|
const signer = this.provider.getSigner()
|
||||||
const address = await signer.getAddress()
|
const address = await signer.getAddress()
|
||||||
await this.updateBalances([address])
|
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)
|
const pollInit = await PollInitMsg.create(signer, question, answers, pollType, this.chainId, minToken, endTime)
|
||||||
if (pollInit) {
|
if (pollInit) {
|
||||||
await this.sendWakuMessage(this.wakuMessages['pollInit'], 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)
|
const poll = this.wakuMessages['pollInit'].arr.find((poll: PollInitMsg): poll is PollInitMsg => poll.id === pollId)
|
||||||
if (poll) {
|
if (poll) {
|
||||||
await this.updateBalances([address])
|
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)
|
const pollVote = await TimedPollVoteMsg.create(signer, pollId, selectedAnswer, this.chainId, tokenAmount)
|
||||||
if (pollVote) {
|
if (pollVote) {
|
||||||
await this.sendWakuMessage(this.wakuMessages['pollVote'], pollVote)
|
await this.sendWakuMessage(this.wakuMessages['pollVote'], pollVote)
|
||||||
|
@ -112,7 +118,7 @@ export class WakuPolling extends WakuMessaging {
|
||||||
.map((poll: PollInitMsg) => {
|
.map((poll: PollInitMsg) => {
|
||||||
if (
|
if (
|
||||||
this.addressesBalances[poll.owner] &&
|
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(
|
return new DetailedTimedPoll(
|
||||||
poll,
|
poll,
|
||||||
|
@ -121,7 +127,7 @@ export class WakuPolling extends WakuMessaging {
|
||||||
(vote: TimedPollVoteMsg) =>
|
(vote: TimedPollVoteMsg) =>
|
||||||
vote.pollId === poll.id &&
|
vote.pollId === poll.id &&
|
||||||
this.addressesBalances[poll.owner] &&
|
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)
|
.filter((e): e is TimedPollVoteMsg => !!e)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue