make forceRedeem to be correctly parsed from the history page; make evm block number dynamically updated
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
b675da56d2
commit
fc043af3e5
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.25",
|
||||
"version": "0.8.26",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import useSWR from 'swr';
|
||||
import { useMemo, useState } from "react";
|
||||
import { useTransactionReceipt, useBlockNumber, useTransaction } from 'wagmi';
|
||||
import { useMemo, useState, useEffect } from "react";
|
||||
import { useTransactionReceipt, useTransaction } from 'wagmi';
|
||||
import { getBlockNumber } from "@wagmi/core";
|
||||
import { decodeEventLog, decodeFunctionData } from 'viem';
|
||||
import { Box, Typography, Link, Skeleton, useTheme } from "@mui/material";
|
||||
import { ss58Encode } from "@polkadot-labs/hdkd-helpers";
|
||||
@ -33,9 +34,31 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
if (historyRecord === null) return null;
|
||||
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [blockNumber, setBlockNumber] = useState(0n);
|
||||
const [copiedIndex, setCopiedIndex] = useState(null);
|
||||
const { casperApi, client, account } = useUnstableProvider();
|
||||
const { data: blockNumber } = useBlockNumber({ watch: true });
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen || !historyRecord || !config) return;
|
||||
let isMounted = true;
|
||||
|
||||
const fetchBlock = async () => {
|
||||
try {
|
||||
const block = await getBlockNumber(config, { chainId });
|
||||
if (isMounted) setBlockNumber(block);
|
||||
} catch (err) {
|
||||
console.error('Error fetching block number:', err);
|
||||
}
|
||||
};
|
||||
|
||||
fetchBlock();
|
||||
const intervalId = setInterval(fetchBlock, 5000);
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
clearInterval(intervalId);
|
||||
};
|
||||
}, [config, chainId, isOpen, historyRecord]);
|
||||
|
||||
const { data: txData } = useTransaction({
|
||||
chainId,
|
||||
@ -66,7 +89,15 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
const receiverRaw = decoded?.args.at(0);
|
||||
const receiver = receiverRaw ? ss58Encode(receiverRaw, prefix) : null;
|
||||
return { receiver, amount: decoded?.args.at(1) };
|
||||
} catch {
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
const decoded = decodeFunctionData({ abi: GhostBondDepositoryAbi, data: txData.input });
|
||||
const prefix = chainProperties.properties.ss58Format;
|
||||
const receiverRaw = decoded?.args.at(0);
|
||||
const receiver = receiverRaw ? ss58Encode(receiverRaw, prefix) : null;
|
||||
return { receiver, amount: 1n, indexes: decoded?.args.at(1) };
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}, [txData, chainProperties]);
|
||||
@ -163,7 +194,7 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
const localString = new Date(historyRecord.submitted).toLocaleString();
|
||||
|
||||
const bridgedAmount = useMemo(() => {
|
||||
if (functionArgs) {
|
||||
if (functionArgs && !Object.hasOwn(functionArgs, 'indexes')) {
|
||||
return new DecimalBigNumber(
|
||||
functionArgs.amount,
|
||||
chainProperties?.properties.tokenDecimals ?? 18
|
||||
@ -190,7 +221,7 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
const incomingShare = networkData ? BigInt(networkData.incoming_share) : 0n;
|
||||
const result = hundredPercent - incomingShare
|
||||
|
||||
if (functionArgs) {
|
||||
if (functionArgs && !Object.hasOwn(functionArgs, 'indexes')) {
|
||||
const value = functionArgs.amount * result / hundredPercent;
|
||||
return new DecimalBigNumber(value, chainProperties.properties.tokenDecimals)
|
||||
} else if (transferInfo) {
|
||||
@ -276,7 +307,7 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
slot_index: weaverArgs.valueIndex,
|
||||
proof_index: weaverArgs.slotIndex,
|
||||
receiver: functionArgs.receiver,
|
||||
amount: functionArgs.amount,
|
||||
amount: bridgedAmount._value,
|
||||
proof: merkleProof,
|
||||
slots: slotValues,
|
||||
}
|
||||
@ -430,7 +461,12 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
disabled={!rootIncluded || isPending || threadPulled === null}
|
||||
disabled={
|
||||
(!functionArgs && !transferInfo) ||
|
||||
!rootIncluded ||
|
||||
isPending ||
|
||||
threadPulled === null
|
||||
}
|
||||
onClick={pullCurrentThread}
|
||||
>
|
||||
{isPending
|
||||
@ -620,7 +656,7 @@ const SyncTarget = ({ weaverAuthorities, networkAttestations, tapestryDraft, sub
|
||||
const syncTargetText = useMemo(() => {
|
||||
if (rootIncluded) return "Synced";
|
||||
|
||||
if (!tapestryDraft || !loomState) {
|
||||
if (!tapestryDraft || !tapestryDraft) {
|
||||
const total = weaverAuthorities ? weaverAuthorities.length : 0;
|
||||
const count = networkAttestations
|
||||
? networkAttestations.filter(v => v !== undefined).length
|
||||
@ -628,9 +664,9 @@ const SyncTarget = ({ weaverAuthorities, networkAttestations, tapestryDraft, sub
|
||||
return `${count} / ${total}`
|
||||
}
|
||||
|
||||
if (submissionBlock < loomState.at_block) return "Synced";
|
||||
if (submissionBlock < tapestryDraft.median) return "Synced";
|
||||
|
||||
return `${formatNumber(Number(submissionBlock - loomState.at_block))} block behind`;
|
||||
return `${formatNumber(Number(submissionBlock - tapestryDraft.median))} blocks behind`;
|
||||
}, [rootIncluded, tapestryDraft, loomState, weaverAuthorities, submissionBlock, networkAttestations]);
|
||||
|
||||
return (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user