Skip to content

Commit

Permalink
fix: prevent withdraw dialog from disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
a0ngo committed Sep 18, 2023
1 parent 6f50354 commit d3a2a02
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { useMemo, useState, ReactNode } from 'react';
import { nanoid } from 'nanoid';
import { Typography, Box } from '@mui/material';
import { VaultAccount, BaseModal, AssetIcon, TransactionInitInput, RelayRxTx } from '@fireblocks/recovery-shared';
import {
VaultAccount,
BaseModal,
AssetIcon,
TransactionInitInput,
RelayRxTx,
getLogger,
wrapState,
} from '@fireblocks/recovery-shared';
import { getAssetConfig, derivableAssets, AssetConfig, getDerivableAssetConfig } from '@fireblocks/asset-config';
import { useWorkspace } from '../../../context/Workspace';
import { InitiateTransaction } from './InitiateTransaction';
import { SignTransaction } from './SignTransaction';
import { LOGGER_NAME_UTILITY } from '@fireblocks/recovery-shared/constants';

type Props = {
assetId?: string;
Expand Down Expand Up @@ -50,9 +59,11 @@ export const WithdrawModal = ({ assetId, accountId, open, onClose: onCloseModal
[accountsArray],
);

const [txInitData, setTxInitData] = useState<TransactionInitInput | null>(null);
const [txInitData, setTxInitDataInt] = useState<TransactionInitInput | null>(null);

const [createTxOutboundRelayUrl, setCreateTxOutboundRelayUrl] = useState<string | null>(null);
const [createTxOutboundRelayUrl, setCreateTxOutboundRelayUrlInt] = useState<string | null>(null);
const setTxInitData = wrapState<TransactionInitInput | null>('txInitData', setTxInitDataInt);
const setCreateTxOutboundRelayUrl = wrapState<string | null>('createTxOutboundRelayUrl', setCreateTxOutboundRelayUrlInt);

const selectedAccount = typeof accountId === 'number' ? accounts.get(accountId) : undefined;

Expand Down Expand Up @@ -118,7 +129,9 @@ export const WithdrawModal = ({ assetId, accountId, open, onClose: onCloseModal
txTitle={`xpub/fpub, account ${txInitData.accountId}, asset ${txInitData.assetId}`}
txUrl={createTxOutboundRelayUrl}
onDecodeQrCode={(data) => {
setInboundRelayUrl(data);
if (!setInboundRelayUrl(data)) {
return;
}
setCreateTxOutboundRelayUrl(null);
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/hooks/useBaseWorkspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultBaseWorkspace: BaseWorkspace<BaseWallet> = {

export const defaultBaseWorkspaceContext: BaseWorkspaceContext<BaseWallet> = {
...defaultBaseWorkspace,
setInboundRelayUrl: () => undefined,
setInboundRelayUrl: () => false,
getOutboundRelayUrl: () => '',
setExtendedKeys: () => undefined,
importCsv: () => Promise.resolve(),
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/hooks/useBaseWorkspace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type BaseWorkspaceContext<
Derivation extends BaseWallet = BaseWallet,
App extends 'utility' | 'relay' = 'utility',
> = BaseWorkspace<Derivation, App> & {
setInboundRelayUrl: (relayUrl: string | null) => void;
setInboundRelayUrl: (relayUrl: string | null) => boolean;
getOutboundRelayUrl: <Params extends App extends 'utility' ? RelayRequestParams : RelayResponseParams>(
params: Params,
) => string;
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/hooks/useBaseWorkspace/useRelayUrl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ export const useRelayUrl = <App extends 'utility' | 'relay'>(app: App, baseUrl:
logger.debug('setInboundRelayUrl', { relayUrl });
if (!relayUrl) {
setInboundRelayParams(undefined);
return false;
} else {
const params = getInboundRelayParams(relayUrl);

setInboundRelayParams(params);
return true;
}
} catch (error) {
logger.error(error);
return false;
}
};

Expand Down

0 comments on commit d3a2a02

Please sign in to comment.