Skip to content

Commit

Permalink
chore: check if bridge is enabled before submitting tx
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Sep 26, 2024
1 parent 302a31d commit ece1718
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions ui/ducks/bridge/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Numeric } from '../../../shared/modules/Numeric';
import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
import {
checkNetworkAndAccountSupports1559,
getIsBridgeEnabled,
getNetworkConfigurations,
getSelectedNetworkClientId,
} from '../../selectors';
Expand Down Expand Up @@ -103,12 +104,12 @@ export const signBridgeTransaction = (
getState: () => MetaMaskReduxState,
) => {
const state = getState();
const isBridgeEnabled = getIsBridgeEnabled(state);

// TODO Check feature flags to see if enabled
// if (!isLive) {
// history.push(BRIDGE_MAINTENANCE_ROUTE);
// return;
// }
if (!isBridgeEnabled) {
// TODO do we want to do something here?
return;
}

const quoteMeta = DUMMY_QUOTES_APPROVAL[0]; // TODO: actually use live quotes
// const quoteMeta = DUMMY_QUOTES_NO_APPROVAL[0]; // TODO: actually use live quotes
Expand Down Expand Up @@ -138,6 +139,10 @@ export const signBridgeTransaction = (
// );
}

const handleUSDTAllowanceReset = () => {
const;
};

const handleApprovalTx = async () => {
console.log('Bridge', 'handleApprovalTx');

Expand All @@ -162,6 +167,9 @@ export const signBridgeTransaction = (
requireApproval: false,
// @ts-expect-error Need TransactionController v37+, TODO add this type
type: 'bridgeApproval', // TransactionType.bridgeApproval,

// TODO update TransactionController to change this to a bridge field
// swaps.meta is of type Partial<TransactionMeta>, will get merged with TransactionMeta by the TransactionController
swaps: {
hasApproveTx: true,
meta: {
Expand Down Expand Up @@ -198,7 +206,9 @@ export const signBridgeTransaction = (
requireApproval: false,
// @ts-expect-error Need TransactionController v37+, TODO add this type
type: 'bridge', // TransactionType.bridge,
bridge: {

// TODO update TransactionController to change this to a bridge field
swaps: {
hasApproveTx: Boolean(quoteMeta?.approval),
meta: {
// estimatedBaseFee: decEstimatedBaseFee,
Expand Down Expand Up @@ -298,22 +308,26 @@ export const signBridgeTransaction = (
}
};

// Execute transaction(s)
let approvalTxId: string | undefined;
if (quoteMeta?.approval) {
approvalTxId = await handleApprovalTx();
}
await handleBridgeTx(approvalTxId);
const execute = async () => {
// Execute transaction(s)
let approvalTxId: string | undefined;
if (quoteMeta?.approval) {
approvalTxId = await handleApprovalTx();
}
await handleBridgeTx(approvalTxId);

// Add tokens if not the native gas token
if (quoteMeta.quote.srcAsset.address !== DEFAULT_TOKEN_ADDRESS) {
addSourceToken();
}
if (quoteMeta.quote.destAsset.address !== DEFAULT_TOKEN_ADDRESS) {
addDestToken();
}
// Add tokens if not the native gas token
if (quoteMeta.quote.srcAsset.address !== DEFAULT_TOKEN_ADDRESS) {
addSourceToken();
}
if (quoteMeta.quote.destAsset.address !== DEFAULT_TOKEN_ADDRESS) {
addDestToken();
}

// Return user to home screen
history.push(DEFAULT_ROUTE);
};

// Return user to home screen
history.push(DEFAULT_ROUTE);
await execute();
};
};

0 comments on commit ece1718

Please sign in to comment.