avoid unmounts during bridge-in because if useSWR
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
b09c6b82f7
commit
e42f5db893
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user