Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DRAFT) feat: swapTo token prepopulate #30024

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
feat: swapTo token prepopualte
ghgoodreau committed Jan 29, 2025
commit edc10f234567c57edcf2bcf3779f96ed2e4fc851
29 changes: 27 additions & 2 deletions ui/pages/swaps/prepare-swap-page/prepare-swap-page.js
Original file line number Diff line number Diff line change
@@ -541,8 +541,33 @@ export default function PrepareSwapPage({
if (!fromToken?.symbol && !fetchParamsFromToken?.symbol) {
dispatch(setSwapsFromToken(defaultSwapsToken));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

console.log('topAssets', topAssets);

// Find first top asset that isn't the from token
const topAssetAddresses = Object.keys(topAssets);
const firstDifferentTopAssetAddress = topAssetAddresses.find(
(address) => !isEqualCaseInsensitive(address, fromToken?.address),
);

// Find matching token in tokensToSearchSwapTo
const defaultToToken = tokensToSearchSwapTo.find((token) =>
isEqualCaseInsensitive(token.address, firstDifferentTopAssetAddress),
);

if (!toToken?.symbol && defaultToToken) {
dispatch(setSwapToToken(defaultToToken));
}
}, [
dispatch,
fromToken?.symbol,
fromToken?.address,
fetchParamsFromToken?.symbol,
defaultSwapsToken,
toToken?.symbol,
tokensToSearchSwapTo,
topAssets,
]);

useEffect(() => {
if (prevFromTokenBalance !== fromTokenBalance) {

Unchanged files with check annotations Beta

// TODO: Re think how to test this without exposing internal state
// it('should replace ethers instance when called with a different chainId than was current when the controller was instantiated', async function () {

Check warning on line 1265 in app/scripts/controllers/swaps/swaps.test.ts

GitHub Actions / Test lint / Test lint

Some tests seem to be commented
// fetchTradesInfoStub.mockReset();
// const _swapsController = getSwapsController();
// expect(currentEthersInstance).not.toStrictEqual(newEthersInstance);
// });
// it('should not replace ethers instance when called with the same chainId that was current when the controller was instantiated', async function () {

Check warning on line 1286 in app/scripts/controllers/swaps/swaps.test.ts

GitHub Actions / Test lint / Test lint

Some tests seem to be commented
// const _swapsController = new SwapsController({
// getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
// provider,
// expect(currentEthersInstance).toStrictEqual(newEthersInstance);
// });
// it('should replace ethers instance, and _ethersProviderChainId, twice when called twice with two different chainIds, and successfully set the _ethersProviderChainId when returning to the original chain', async function () {

Check warning on line 1306 in app/scripts/controllers/swaps/swaps.test.ts

GitHub Actions / Test lint / Test lint

Some tests seem to be commented
// const _swapsController = new SwapsController({
// getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
// provider,
});
});
// it('clears polling timeout', function () {

Check warning on line 1390 in app/scripts/controllers/swaps/swaps.test.ts

GitHub Actions / Test lint / Test lint

Some tests seem to be commented
// swapsController._pollingTimeout = setTimeout(() => {
// throw new Error('Polling timeout not cleared');
// }, POLLING_TIMEOUT);
describe('stopPollingForQuotes', function () {
// TODO: Re think how to test this without exposing internal state
// it('clears polling timeout', function () {

Check warning on line 1406 in app/scripts/controllers/swaps/swaps.test.ts

GitHub Actions / Test lint / Test lint

Some tests seem to be commented
// swapsController._pollingTimeout = setTimeout(() => {
// throw new Error('Polling timeout not cleared');
// }, POLLING_TIMEOUT);
describe('resetPostFetchState', function () {
// TODO: Re think how to test this without exposing internal state
// it('clears polling timeout', function () {

Check warning on line 1429 in app/scripts/controllers/swaps/swaps.test.ts

GitHub Actions / Test lint / Test lint

Some tests seem to be commented
// swapsController._pollingTimeout = setTimeout(() => {
// throw new Error('Polling timeout not cleared');
// }, POLLING_TIMEOUT);
.forPost(SOLANA_URL_REGEX)
.withJsonBodyIncluding({
method: 'getLatestBlockhash',
})

Check warning on line 91 in test/e2e/flask/solana/common-solana.ts

GitHub Actions / Test lint / Test lint

'#fb9f18' Hex color values are not allowed. Consider using design tokens instead. For support reach out to the design system team #metamask-design-system on Slack
.thenCallback(() => {
return response;
});
};
setTokensListDetected(newTokensList());
}, [

Check warning on line 117 in ui/components/app/detected-token/detected-token.js

GitHub Actions / Test lint / Test lint

React Hook useEffect has a missing dependency: 'tokensListDetected'. Either include it or remove the dependency array
isTokenNetworkFilterEqualCurrentNetwork,
detectedTokensMultichain,
detectedTokens,
* No name has been saved for the value and type.
*/
export const NoSavedName = {
name: 'No Saved Name',

Check warning on line 129 in ui/components/app/name/name.stories.tsx

GitHub Actions / Test lint / Test lint

Named exports should not use the name annotation if it is redundant to the name that would be generated by the export name
args: {
value: ADDRESS_MOCK,
type: NameType.ETHEREUM_ADDRESS,
useEffect(() => {
return () => interfaceId && dispatch(deleteInterface(interfaceId));
}, [interfaceId]);

Check warning on line 49 in ui/components/app/snaps/snap-home-page/snap-home-renderer.js

GitHub Actions / Test lint / Test lint

React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array
useEffect(() => {
// Snaps are allowed to redirect to their own pending confirmations (templated or not)