Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/stable-branch-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:
run-stable-sync:
name: Run Stable branch sync
needs: get-next-version
uses: metamask/github-tools/.github/workflows/stable-sync.yml@486f5d113c5524eaab9a058abe76097f83a4c33e
uses: metamask/github-tools/.github/workflows/stable-sync.yml@701a894f38883ab48560f948e98b76cc6b4d623f
secrets:
github-token: ${{ secrets.STABLE_SYNC_TOKEN }}
with:
semver-version: ${{ needs.get-next-version.outputs.next-version }}
repo-type: 'mobile' # Accepts 'mobile' or 'extension'
github-tools-version: '486f5d113c5524eaab9a058abe76097f83a4c33e'
github-tools-version: '701a894f38883ab48560f948e98b76cc6b4d623f'
stable-branch-name: 'stable'
23 changes: 22 additions & 1 deletion app/components/UI/Bridge/hooks/useBridgeQuoteRequest/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useRef, useEffect } from 'react';
import Engine from '../../../../../core/Engine';
import { type GenericQuoteRequest } from '@metamask/bridge-controller';
import { useSelector } from 'react-redux';
Expand All @@ -16,6 +16,8 @@ import { debounce } from 'lodash';
import { useUnifiedSwapBridgeContext } from '../useUnifiedSwapBridgeContext';
import { selectShouldUseSmartTransaction } from '../../../../../selectors/smartTransactionsController';
import { selectSourceWalletAddress } from '../../../../../selectors/bridge';
import useIsInsufficientBalance from '../useInsufficientBalance';
import { useLatestBalance } from '../useLatestBalance';

export const DEBOUNCE_WAIT = 300;

Expand All @@ -35,6 +37,24 @@ export const useBridgeQuoteRequest = () => {
const shouldUseSmartTransaction = useSelector(
selectShouldUseSmartTransaction,
);

const latestSourceBalance = useLatestBalance({
address: sourceToken?.address,
decimals: sourceToken?.decimals,
chainId: sourceToken?.chainId,
});
const insufficientBal = useIsInsufficientBalance({
amount: sourceAmount,
token: sourceToken,
latestAtomicBalance: latestSourceBalance?.atomicBalance,
});

// Use a ref to track the latest insufficientBal value without triggering callback recreation
const insufficientBalRef = useRef(insufficientBal);
useEffect(() => {
insufficientBalRef.current = insufficientBal;
}, [insufficientBal]);

/**
* Updates quote parameters in the bridge controller
*/
Expand Down Expand Up @@ -68,6 +88,7 @@ export const useBridgeQuoteRequest = () => {
destWalletAddress: destAddress ?? walletAddress,
gasIncluded: shouldUseSmartTransaction,
gasIncluded7702: false, // TODO research how to handle this
insufficientBal: insufficientBalRef.current,
};

await Engine.context.BridgeController.updateBridgeQuoteRequestParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ jest.mock('../../../../../core/Engine', () => ({
],
},
},
NetworkController: {
findNetworkClientIdByChainId: jest.fn(() => 'mainnet'),
getNetworkClientById: jest.fn(() => ({
provider: {
request: jest.fn(),
sendAsync: jest.fn(),
},
configuration: {
chainId: '0x1',
},
})),
},
},
}));

Expand Down
Loading
Loading