Skip to content

Commit

Permalink
Merge pull request #337 from pendulum-chain/fix-restore-offramp
Browse files Browse the repository at this point in the history
Fix restoring offramp after a refresh
  • Loading branch information
gianfra-t authored Dec 23, 2024
2 parents d632cb4 + 8b6e457 commit 6b85d3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/hooks/offramp/useMainProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { OFFRAMPING_PHASE_SECONDS } from '../../pages/progress';
import { createTransactionEvent, useEventsContext } from '../../contexts/events';
import { useAssetHubNode, usePendulumNode } from '../../contexts/polkadotNode';
import { usePolkadotWalletState } from '../../contexts/polkadotWallet';
import { useNetwork } from '../../contexts/network';
import { Networks, useNetwork } from '../../contexts/network';

import {
clearOfframpingState,
Expand Down Expand Up @@ -129,10 +129,6 @@ export const useMainProcess = () => {
setSigningPhase,
]);

useEffect(() => {
setOnSelectedNetworkChange(resetOfframpingState);
}, [setOnSelectedNetworkChange, resetOfframpingState]);

const handleOnAnchorWindowOpen = useCallback(async () => {
if (!pendulumNode) {
console.error('Pendulum node not initialized');
Expand All @@ -144,7 +140,7 @@ export const useMainProcess = () => {

const finishOfframping = useCallback(() => {
(async () => {
await clearOfframpingState();
clearOfframpingState();
resetUniqueEvents();
setOfframpingStarted(false);
updateHookStateFromState(undefined);
Expand All @@ -157,7 +153,8 @@ export const useMainProcess = () => {
}, [updateHookStateFromState, offrampingState]);

useEffect(() => {
if (wagmiConfig.state.status !== 'connected') return;
if (selectedNetwork == Networks.Polygon && wagmiConfig.state.status !== 'connected') return;
if (selectedNetwork == Networks.AssetHub && !walletAccount?.address) return;

(async () => {
if (!pendulumNode || !assetHubNode) {
Expand All @@ -179,11 +176,17 @@ export const useMainProcess = () => {
updateHookStateFromState(nextState);
}
})();
// This effect has dependencies that are used inside the async function (assetHubNode, pendulumNode, walletAccount)
// but we intentionally exclude them from the dependency array to prevent unnecessary re-renders.
// These dependencies are stable and won't change during the lifecycle of this hook.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [offrampingState, trackEvent, updateHookStateFromState, wagmiConfig]);
}, [
offrampingState,
trackEvent,
updateHookStateFromState,
wagmiConfig,
pendulumNode,
assetHubNode,
wagmiConfig.state.status,
walletAccount?.address,
]);

const maybeCancelSep24First = useCallback(() => {
if (firstSep24IntervalRef.current !== undefined) {
Expand Down
1 change: 0 additions & 1 deletion src/services/phases/polkadot/spacewalk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export class VaultService {
options.era = 0;

const stellarPkBytes = Uint8Array.from(stellarPkBytesBuffer);

return this.apiComponents!.api.tx.redeem.requestRedeem(amountRaw, stellarPkBytes, this.vaultId!).signAsync(
addressOrPair,
options,
Expand Down

0 comments on commit 6b85d3c

Please sign in to comment.