Skip to content

Commit

Permalink
swaps: revert entry point (#5247)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylarbarrera authored Dec 14, 2023
1 parent 8b54d8e commit a7c057e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ import {
import { CurrencySelectionTypes, ExchangeModalTypes } from '@/helpers';
import {
useAccountProfile,
useAccountSettings,
useSwapCurrencyHandlers,
useWallets,
} from '@/hooks';
import { delayNext } from '@/hooks/useMagicAutofocus';
import { useNavigation } from '@/navigation';
import { watchingAlert } from '@/utils';
import { ethereumUtils, watchingAlert } from '@/utils';
import Routes from '@rainbow-me/routes';
import showWalletErrorAlert from '@/helpers/support';
import { analytics } from '@/analytics';
import { useRecoilState } from 'recoil';
import config from '@/model/config';
import { useAccountAccentColor } from '@/hooks/useAccountAccentColor';
import { addressCopiedToastAtom } from '@/recoil/addressCopiedToastAtom';
import { Network } from '@/networks/types';

export const ProfileActionButtonsRowHeight = 80;

Expand Down Expand Up @@ -194,35 +196,32 @@ function BuyButton() {

function SwapButton() {
const { isReadOnlyWallet } = useWallets();
const { accountAddress } = useAccountSettings();

const { navigate } = useNavigation();

const { updateInputCurrency } = useSwapCurrencyHandlers({
shouldUpdate: false,
type: ExchangeModalTypes.swap,
});

const handlePress = React.useCallback(() => {
const handlePress = React.useCallback(async () => {
if (!isReadOnlyWallet || enableActionsOnReadOnlyWallet) {
analytics.track('Tapped "Swap"', {
category: 'home screen',
});

android && delayNext();
const mainnetEth = await ethereumUtils.getNativeAssetForNetwork(
Network.mainnet,
accountAddress
);
navigate(Routes.EXCHANGE_MODAL, {
fromDiscover: true,
params: {
fromDiscover: true,
onSelectCurrency: updateInputCurrency,
title: lang.t('swap.modal_types.swap'),
type: CurrencySelectionTypes.input,
inputAsset: mainnetEth,
},
screen: Routes.CURRENCY_SELECT_SCREEN,
screen: Routes.MAIN_EXCHANGE_SCREEN,
});
} else {
watchingAlert();
}
}, [isReadOnlyWallet, navigate, updateInputCurrency]);
}, [accountAddress, isReadOnlyWallet, navigate]);

return (
<ActionButton icon="􀖅" onPress={handlePress} testID="swap-button">
Expand Down
25 changes: 4 additions & 21 deletions src/components/sheet/sheet-action-buttons/SwapActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,24 @@ function SwapActionButton({
if (params.outputAsset) {
return {
params: {
chainId: ethereumUtils.getChainIdFromType(asset.type),
defaultOutputAsset: asset,
fromDiscover: true,
onSelectCurrency: updateInputCurrency,
params: {
...params,
ignoreInitialTypeCheck: true,
outputAsset: asset,
},
showCoinIcon: true,
title: lang.t('swap.modal_types.get_symbol_with', {
symbol: params?.outputAsset?.symbol,
}),
type: CurrencySelectionTypes.input,
},
screen: Routes.CURRENCY_SELECT_SCREEN,
screen: Routes.MAIN_EXCHANGE_SCREEN,
};
} else {
console.log(asset);
return {
params: {
chainId: ethereumUtils.getChainIdFromType(asset.type),
defaultInputAsset: asset,
onSelectCurrency: updateOutputCurrency,
params: {
...params,
ignoreInitialTypeCheck: true,
},
title: lang.t('swap.modal_types.receive'),
type: CurrencySelectionTypes.output,
},
screen: Routes.CURRENCY_SELECT_SCREEN,
screen: Routes.MAIN_EXCHANGE_SCREEN,
};
}
});
}, [asset, navigate, updateInputCurrency, updateOutputCurrency]);
}, [asset, navigate]);

return (
<SheetActionButton
Expand Down
1 change: 1 addition & 0 deletions src/screens/ExchangeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export default function ExchangeModal({
crosschainSwapsEnabled,
inputCurrency?.symbol,
inputCurrency?.type,
network,
outputCurrency?.symbol,
outputCurrency?.type,
]);
Expand Down

0 comments on commit a7c057e

Please sign in to comment.