diff --git a/package.json b/package.json index 26666fe..b3c3506 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "phantasma-hub", - "version": "1.0.4", + "version": "1.0.5", "private": true, "scripts": { "dev": "npm run version:update && vite dev --cors true", diff --git a/src/lib/Components/Votes/PollDetails.svelte b/src/lib/Components/Votes/PollDetails.svelte index c1d5505..8a2d6ff 100644 --- a/src/lib/Components/Votes/PollDetails.svelte +++ b/src/lib/Components/Votes/PollDetails.svelte @@ -2,7 +2,7 @@ import Card from '$lib/Components/Card/Card.svelte'; import { singleVote } from '$lib/Components/Wallet/VoteCommands'; import moment from 'moment'; - import { beforeUpdate, onMount, tick } from 'svelte'; + import { beforeUpdate, afterUpdate, onMount, tick } from 'svelte'; import { DateTimeFormat, LinkWallet } from '$lib/store'; import { ConsensusMode, @@ -13,7 +13,7 @@ PollState, PollValue, Timestamp - } from 'phantasma-ts'; + } from 'phantasma-ts/src'; //import { e } from 'vitest/dist/index-5aad25c1'; /** @@ -33,30 +33,30 @@ let startTime; let endTime; - let timeNow: number = Timestamp.now / 1000; + let timeNow: number = Date.now() / 1000; let choices: PollChoice[] = new Array(); let entries: PollValue[] = new Array(); let selected; - beforeUpdate(async () => { - initDates(); - initChoices(); - initPollState(); + afterUpdate(async () => { + Init(); }); function initDates() { + console.log('Init dates'); startTime = moment(poll.startTime.value * 1000).format(DateTimeFormat); endTime = moment(poll.endTime.value * 1000).format(DateTimeFormat); } function initChoices() { + console.log('Init choices'); choices = new Array(); entries = new Array(); entries = poll.entries; - for (let i = 0; i < poll.entries.length; i++) { + /*for (let i = 0; i < poll.entries.length; i++) { let choice: PollChoice = new PollChoice(''); let entry = poll.entries[i] as unknown as string; //let bytes = Base16.decodeUint8Array(entry); @@ -65,7 +65,7 @@ //pollValue.UnserializeData(reader); choice.value = poll.entries[i].value; // Base16.decode(uint8ArrayToStringDefault()); choices.push(choice); - } + }*/ for (let entry in poll.entries) { /*let reader: PBinaryReader = new PBinaryReader( @@ -90,6 +90,7 @@ } function initPollState() { + console.log('Init Poll State'); if (PollState.Inactive == poll.state) { console.log( poll.startTime.value <= timeNow, @@ -106,15 +107,19 @@ } } - initDates(); - initChoices(); - initPollState(); + function Init() { + initDates(); + initChoices(); + initPollState(); + } + + Init(); = Date.now() ? ` (Finish ${moment(poll.endTime.value * 1000).fromNow()})` : ''}." > @@ -206,7 +211,7 @@ {#each Object.keys(ConsensusMode) .map((key) => ConsensusMode[key]) .filter((value) => typeof value === 'string') as m} - {#if poll.mode == ConsensusMode[m]} + {#if ConsensusMode[poll.mode] == ConsensusMode[m]} {:else} diff --git a/src/lib/Components/Wallet/VoteCommands.ts b/src/lib/Components/Wallet/VoteCommands.ts index 967a5bc..26fa400 100644 --- a/src/lib/Components/Wallet/VoteCommands.ts +++ b/src/lib/Components/Wallet/VoteCommands.ts @@ -3,19 +3,19 @@ import { byteArrayToHex, PBinaryWriter, PhantasmaAPI, - PollChoice, ScriptBuilder, Transaction, Base16, - ConsensusMode, - ConsensusPoll, - PBinaryReader, Serialization, Timestamp, - VMObject + PBinaryReader, + VMObject, + ConsensusMode, + ConsensusPoll, + PollChoice } from 'phantasma-ts/src'; import { GasLimit, GasPrice, IsPollCreated, LinkWallet, PhantasmaAPIClient } from '$lib/store'; -import type { PhantasmaLink } from 'phantasma-ts'; +import { PhantasmaLink } from 'phantasma-ts'; import { NotificationError, NotificationSuccess @@ -263,6 +263,7 @@ export async function getConsensusPolls() { const binaryReader = new PBinaryReader(Base16.decodeUint8Array(test[i])); //const consensusPoll : ConsensusPoll = vm.ToStruct(ConsensusPoll); const consensusPoll : ConsensusPoll = ConsensusPoll.Unserialize(binaryReader); + console.log(consensusPoll); results.push(consensusPoll); } diff --git a/src/routes/votes/+page.svelte b/src/routes/votes/+page.svelte index dc85749..6fb2f5e 100644 --- a/src/routes/votes/+page.svelte +++ b/src/routes/votes/+page.svelte @@ -5,7 +5,7 @@ import PollDetails from '$lib/Components/Votes/PollDetails.svelte'; import { getConsensusPoll, getConsensusPolls } from '$lib/Components/Wallet/VoteCommands'; import { IsPollCreated, PhantasmaAPIClient } from '$lib/store'; - import type { type ConsensusPoll, Organization, PhantasmaAPI } from 'phantasma-ts/src'; + import type { ConsensusPoll, Organization, PhantasmaAPI } from 'phantasma-ts/src'; let api: PhantasmaAPI; PhantasmaAPIClient.subscribe(async (value) => {