Skip to content

Commit

Permalink
Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisassad committed Nov 18, 2024
1 parent 3709179 commit 400ab68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 10 additions & 6 deletions packages/commonwealth/client/scripts/helpers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import BigNumber from 'bignumber.js';
import moment from 'moment';
import React from 'react';
import Account from '../models/Account';
import { IBlockInfo } from '../models/interfaces';
import { ThreadStage } from '../models/types';
import type { IApp } from '../state/index';

Expand Down Expand Up @@ -178,16 +179,19 @@ export function renderMultilineText(text: string) {
* blocknum helpers
*/

export function blocknumToTime(app: IApp, blocknum: number): moment.Moment {
const currentBlocknum = app.chain.block.height;
const blocktime = app.chain.block.duration;
const lastBlockTime: moment.Moment = app.chain.block.lastTime.clone();
export function blocknumToTime(
block: IBlockInfo,
blocknum: number,
): moment.Moment {
const currentBlocknum = block.height;
const blocktime = block.duration;
const lastBlockTime: moment.Moment = block.lastTime.clone();
return lastBlockTime.add((blocknum - currentBlocknum) * blocktime, 'seconds');
}

export function blocknumToDuration(app: IApp, blocknum: number) {
export function blocknumToDuration(block: IBlockInfo, blocknum: number) {
return moment
.duration(blocknumToTime(app, blocknum).diff(moment()))
.duration(blocknumToTime(block, blocknum).diff(moment()))
.asMilliseconds();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export const getStatusText = (proposal: AnyProposal, isLoading?: boolean) => {
? [
<Countdown
key={proposal.endTime.kind}
duration={blocknumToDuration(app, proposal.endTime.blocknum)}
duration={blocknumToDuration(
app.chain.block,
proposal.endTime.blocknum,
)}
/>,
` left (ends on block ${formatNumberLong(
proposal.endTime.blocknum,
Expand All @@ -60,7 +63,7 @@ export const getStatusText = (proposal: AnyProposal, isLoading?: boolean) => {
<Countdown
key={proposal.endTime.kind}
duration={blocknumToDuration(
app,
app.chain.block,
proposal.endTime.getBlocknum(),
)}
/>,
Expand Down

0 comments on commit 400ab68

Please sign in to comment.