Have execute button show up when ready using a set interval trick.

This commit is contained in:
Dummy Tester 123 2021-03-20 16:58:06 -05:00
parent f68560ea35
commit b8262223d3
1 changed files with 17 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import {
import { ParsedAccount, contexts } from '@oyster/common'; import { ParsedAccount, contexts } from '@oyster/common';
import { Card, Spin } from 'antd'; import { Card, Spin } from 'antd';
import Meta from 'antd/lib/card/Meta'; import Meta from 'antd/lib/card/Meta';
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { execute } from '../../actions/execute'; import { execute } from '../../actions/execute';
import { LABELS } from '../../constants'; import { LABELS } from '../../constants';
import { import {
@ -96,7 +96,21 @@ function PlayStatusButton({
const wallet = useWallet(); const wallet = useWallet();
const connection = useConnection(); const connection = useConnection();
const [currSlot, setCurrSlot] = useState(0); const [currSlot, setCurrSlot] = useState(0);
connection.getSlot().then(setCurrSlot);
const elapsedTime = currSlot - proposal.info.state.votingEndedAt.toNumber();
const ineligibleToSee = elapsedTime < instruction.info.slot.toNumber();
useEffect(() => {
if (ineligibleToSee) {
const id = setInterval(() => {
connection.getSlot().then(setCurrSlot);
}, 400);
return () => {
clearInterval(id);
};
}
}, [ineligibleToSee, connection]);
const run = async () => { const run = async () => {
setPlaying(Playstate.Playing); setPlaying(Playstate.Playing);
@ -111,8 +125,7 @@ function PlayStatusButton({
}; };
if (proposal.info.state.status != TimelockStateStatus.Executing) return null; if (proposal.info.state.status != TimelockStateStatus.Executing) return null;
const elapsedTime = currSlot - proposal.info.state.votingEndedAt.toNumber(); if (ineligibleToSee) return null;
if (elapsedTime < instruction.info.slot.toNumber()) return null;
if (playing === Playstate.Unplayed) if (playing === Playstate.Unplayed)
return ( return (