diff --git a/package.json b/package.json index 4e62fdc..b88a84e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.8.1", + "version": "0.8.2", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/Bridge/BridgeIn.jsx b/src/containers/Bridge/BridgeIn.jsx index d949a45..4014c72 100644 --- a/src/containers/Bridge/BridgeIn.jsx +++ b/src/containers/Bridge/BridgeIn.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState, useMemo, useCallback } from "react"; +import { useEffect, useState, useMemo, useCallback, useRef } from "react"; import { useLocation } from "react-router-dom"; import { ss58Decode } from "@polkadot-labs/hdkd-helpers"; import { toHex } from "@polkadot-api/utils"; @@ -296,6 +296,26 @@ const BridgeIn = ({ chainId, address, config, connect }) => { return isPending || differentGatekeepers || smallAmount || insufficientAmount || !receiverHex }, [isPending, networkData, gatekeeperAddress, existentialDeposit, preparedAmount, ghstBalance, receiverHex]); + const latestRef = useRef({ + chainId, + address, + receiverHex, + preparedAmount, + tryStoreInHistory, + ghstBalanceRefetch + }); + + useEffect(() => { + latestRef.current = { + chainId, + address, + receiverHex, + preparedAmount, + tryStoreInHistory, + ghstBalanceRefetch + }; + }); + const setFormatDecimals = useCallback((value) => { if (Number(value) <= 17) { setStorageValue(chainId, address, DECIMALS_PREFIX, value); @@ -304,11 +324,35 @@ const BridgeIn = ({ chainId, address, config, connect }) => { const startGhostBridge = async () => { setIsPending(true); + + const { + chainId: currentChainId, + address: currentAddress, + receiverHex: currentReceiverHex, + preparedAmount: currentPreparedAmount, + tryStoreInHistory: currentTryStoreInHistory, + ghstBalanceRefetch: currentGhstBalanceRefetch + } = latestRef.current; + try { - const txHash = await ghost(chainId, address, receiverHex, preparedAmount._value); - if (txHash) tryStoreInHistory(chainId, address, CONSTANTS.bridgeIn.key, txHash, CONSTANTS.bridgeIn.name); + const txHash = await ghost( + currentChainId, + currentAddress, + currentReceiverHex, + currentPreparedAmount._value + ); + + if (txHash) { + currentTryStoreInHistory( + currentChainId, + currentAddress, + CONSTANTS.bridgeIn.key, + txHash, + CONSTANTS.bridgeIn.name + ); + } } finally { - await ghstBalanceRefetch(); + await currentGhstBalanceRefetch(); setAmount(""); setIsPending(false); } diff --git a/src/hooks/ghost/UnstableProvider.jsx b/src/hooks/ghost/UnstableProvider.jsx index 0da6a07..7bd3139 100644 --- a/src/hooks/ghost/UnstableProvider.jsx +++ b/src/hooks/ghost/UnstableProvider.jsx @@ -76,6 +76,9 @@ export const UnstableProviderProvider = ({ children }) => { useEffect(() => { if (!selectedExtension) return; + const extensionAccounts = selectedExtension.getAccounts(); + setAccounts(extensionAccounts) + const unsubscribe = selectedExtension.subscribe((updatedAccounts) => { setAccounts(updatedAccounts); });