mirror of
https://github.com/status-im/dappconnect-vote-poll-sdk.git
synced 2025-01-14 15:25:07 +00:00
commit
ad16693915
@ -11,7 +11,9 @@ import { WakuMessaging } from './WakuMessaging'
|
|||||||
import { Web3Provider } from '@ethersproject/providers'
|
import { Web3Provider } from '@ethersproject/providers'
|
||||||
import { WakuMessagesSetup } from '../types/WakuMessagesSetup'
|
import { WakuMessagesSetup } from '../types/WakuMessagesSetup'
|
||||||
|
|
||||||
export enum MESSEGAGE_SENDING_RESULT {
|
const MinTokenDefaultValue = BigNumber.from(1)
|
||||||
|
|
||||||
|
export enum MESSAGE_SENDING_RESULT {
|
||||||
ok = 0,
|
ok = 0,
|
||||||
notEnoughToken = 1,
|
notEnoughToken = 1,
|
||||||
errorCreatingMessage = 2,
|
errorCreatingMessage = 2,
|
||||||
@ -72,16 +74,17 @@ 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)
|
||||||
return MESSEGAGE_SENDING_RESULT.ok
|
return MESSAGE_SENDING_RESULT.ok
|
||||||
} else {
|
} else {
|
||||||
return MESSEGAGE_SENDING_RESULT.errorCreatingMessage
|
return MESSAGE_SENDING_RESULT.errorCreatingMessage
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return MESSEGAGE_SENDING_RESULT.notEnoughToken
|
return MESSAGE_SENDING_RESULT.notEnoughToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,18 +94,21 @@ 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)
|
||||||
} else {
|
} else {
|
||||||
return MESSEGAGE_SENDING_RESULT.errorCreatingMessage
|
return MESSAGE_SENDING_RESULT.errorCreatingMessage
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return MESSEGAGE_SENDING_RESULT.notEnoughToken
|
return MESSAGE_SENDING_RESULT.notEnoughToken
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return MESSEGAGE_SENDING_RESULT.pollNotFound
|
return MESSAGE_SENDING_RESULT.pollNotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"clean:all": "yarn clean && rimraf node_modules/",
|
"clean:all": "yarn clean && rimraf node_modules/",
|
||||||
"clean": "rimraf dist/",
|
"clean": "rimraf dist/",
|
||||||
"build": "rm -rf dist && webpack --mode=production --env ENV=production",
|
"build": "rm -rf dist && webpack --mode=production --env ENV=production",
|
||||||
"start": "webpack serve --mode=development --env ENV=development --https",
|
"start": "webpack serve --mode=development --env ENV=development --https --port 8181",
|
||||||
"test": "mocha -r jsdom-global/register",
|
"test": "mocha -r jsdom-global/register",
|
||||||
"lint": "yarn lint:prettier --check && yarn lint:eslint",
|
"lint": "yarn lint:prettier --check && yarn lint:eslint",
|
||||||
"lint:fix": "yarn lint:prettier --write && yarn lint:eslint --fix",
|
"lint:fix": "yarn lint:prettier --write && yarn lint:eslint --fix",
|
||||||
|
@ -3,6 +3,7 @@ import styled from 'styled-components'
|
|||||||
import { PollType } from '@dappconnect/vote-poll-sdk-core/dist/esm/src/types/PollType'
|
import { PollType } from '@dappconnect/vote-poll-sdk-core/dist/esm/src/types/PollType'
|
||||||
import { WakuPolling } from '@dappconnect/vote-poll-sdk-core'
|
import { WakuPolling } from '@dappconnect/vote-poll-sdk-core'
|
||||||
import { Input, addIcon, SmallButton, Modal, Theme } from '@dappconnect/vote-poll-sdk-react-components'
|
import { Input, addIcon, SmallButton, Modal, Theme } from '@dappconnect/vote-poll-sdk-react-components'
|
||||||
|
import { MESSAGE_SENDING_RESULT } from '@dappconnect/vote-poll-sdk-core/dist/esm/src/classes/WakuPolling'
|
||||||
|
|
||||||
function getLocaleIsoTime(dateTime: Date) {
|
function getLocaleIsoTime(dateTime: Date) {
|
||||||
const MS_PER_MINUTE = 60000
|
const MS_PER_MINUTE = 60000
|
||||||
@ -92,10 +93,10 @@ export function PollCreation({ wakuPolling, theme, setShowPollCreation }: PollCr
|
|||||||
undefined,
|
undefined,
|
||||||
endTimePicker.getTime()
|
endTimePicker.getTime()
|
||||||
)
|
)
|
||||||
if (result === 0) {
|
if (result === MESSAGE_SENDING_RESULT.ok) {
|
||||||
setShowCreateConfirmation(true)
|
setShowCreateConfirmation(true)
|
||||||
}
|
}
|
||||||
if (result === 1) {
|
if (result === MESSAGE_SENDING_RESULT.notEnoughToken) {
|
||||||
setShowNotEnoughTokens(true)
|
setShowNotEnoughTokens(true)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user