-
Notifications
You must be signed in to change notification settings - Fork 635
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
Add entry point for other networks #5824
Changes from 2 commits
04bd813
ad68886
32182ed
143ce76
ff2db74
35b3c2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,9 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { | |
const selectedOutputChainId = useSharedValue<ChainId>(initialSelectedInputAsset?.chainId || ChainId.mainnet); | ||
const quote = useSharedValue<Quote | CrosschainQuote | QuoteError | null>(null); | ||
|
||
const inputProgress = useSharedValue(NavigationSteps.INPUT_ELEMENT_FOCUSED); | ||
const inputProgress = useSharedValue( | ||
initialSelectedOutputAsset && !initialSelectedInputAsset ? NavigationSteps.TOKEN_LIST_FOCUSED : NavigationSteps.INPUT_ELEMENT_FOCUSED | ||
); | ||
Comment on lines
+130
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for cases where we have an output asset but no initial input asset |
||
const outputProgress = useSharedValue( | ||
initialSelectedOutputAsset ? NavigationSteps.INPUT_ELEMENT_FOCUSED : NavigationSteps.TOKEN_LIST_FOCUSED | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,9 @@ export const countDecimalPlaces = (number: number | string): number => { | |
|
||
export const findNiceIncrement = (availableBalance: string | number) => { | ||
'worklet'; | ||
if (Number(availableBalance) === 0) { | ||
return 0; | ||
} | ||
Comment on lines
+152
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might not be needed with the NaN check I added, but does this hurt anything to have here? |
||
|
||
// We'll use one of these factors to adjust the base increment | ||
// These factors are chosen to: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,14 @@ import ContextMenuButton from '@/components/native-context-menu/contextMenu'; | |
import { implementation } from '@/entities/dispersion'; | ||
import { RainbowNetworks, getNetworkObj } from '@/networks'; | ||
import { EthCoinIcon } from '../coin-icon/EthCoinIcon'; | ||
import { SWAPS_V2, useExperimentalFlag } from '@/config'; | ||
import { useRemoteConfig } from '@/model/remoteConfig'; | ||
import { userAssetsStore } from '@/state/assets/userAssets'; | ||
import { parseSearchAsset } from '@/__swaps__/utils/assets'; | ||
import { AddressOrEth, AssetType } from '@/__swaps__/types/assets'; | ||
import { chainNameFromChainId } from '@/__swaps__/utils/chains'; | ||
import { swapsStore } from '@/state/swaps/swapsStore'; | ||
import { InteractionManager } from 'react-native'; | ||
|
||
const NOOP = () => null; | ||
|
||
|
@@ -33,6 +41,8 @@ const AvailableNetworksv2 = ({ | |
}) => { | ||
const { colors } = useTheme(); | ||
const { goBack, navigate } = useNavigation(); | ||
const { swaps_v2 } = useRemoteConfig(); | ||
const swapsV2Enabled = useExperimentalFlag(SWAPS_V2); | ||
|
||
const radialGradientProps = { | ||
center: [0, 1], | ||
|
@@ -62,10 +72,65 @@ const AvailableNetworksv2 = ({ | |
// we need to convert the mainnet asset to the selected network's | ||
newAsset.mainnet_address = networks?.[ethereumUtils.getChainIdFromNetwork(Network.mainnet)]?.address ?? asset.address; | ||
newAsset.address = networks?.[ethereumUtils.getChainIdFromNetwork(chosenNetwork)].address; | ||
newAsset.network = chosenNetwork; | ||
|
||
goBack(); | ||
|
||
if (swapsV2Enabled || swaps_v2) { | ||
const chainId = ethereumUtils.getChainIdFromNetwork(newAsset.network); | ||
const uniqueId = `${newAsset.address}_${chainId}`; | ||
const userAsset = userAssetsStore.getState().userAssets.get(uniqueId); | ||
|
||
console.log(chainId, uniqueId); | ||
walmat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const parsedAsset = parseSearchAsset({ | ||
assetWithPrice: { | ||
...newAsset, | ||
uniqueId, | ||
address: newAsset.address as AddressOrEth, | ||
type: newAsset.type as AssetType, | ||
chainId, | ||
chainName: chainNameFromChainId(chainId), | ||
isNativeAsset: false, | ||
native: {}, | ||
}, | ||
searchAsset: { | ||
...newAsset, | ||
uniqueId, | ||
chainId, | ||
chainName: chainNameFromChainId(chainId), | ||
address: newAsset.address as AddressOrEth, | ||
highLiquidity: newAsset.highLiquidity ?? false, | ||
isRainbowCurated: newAsset.isRainbowCurated ?? false, | ||
isVerified: newAsset.isVerified ?? false, | ||
mainnetAddress: (newAsset.mainnet_address ?? '') as AddressOrEth, | ||
networks: newAsset.networks ?? [], | ||
type: newAsset.type as AssetType, | ||
}, | ||
userAsset, | ||
}); | ||
|
||
const largestBalanceSameChainUserAsset = userAssetsStore | ||
.getState() | ||
.getUserAssets() | ||
.find(userAsset => userAsset.chainId === chainId && userAsset.address !== newAsset.address); | ||
if (largestBalanceSameChainUserAsset) { | ||
swapsStore.setState({ inputAsset: largestBalanceSameChainUserAsset }); | ||
} else { | ||
swapsStore.setState({ inputAsset: null }); | ||
} | ||
Comment on lines
+117
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @christianbaroni I can remove this, but I noticed for cases where we don't have a largest balance on the same chain we still default to the largest overall balance. Is that intended? My thinking is it'd make more sense for users to explicitly select an asset so that we aren't making an initial quote fetch that they (probably) don't want. |
||
swapsStore.setState({ outputAsset: parsedAsset }); | ||
|
||
InteractionManager.runAfterInteractions(() => { | ||
navigate(Routes.SWAP); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
newAsset.uniqueId = `${asset.address}_${chosenNetwork}`; | ||
newAsset.type = chosenNetwork; | ||
|
||
goBack(); | ||
navigate(Routes.EXCHANGE_MODAL, { | ||
params: { | ||
fromDiscover: true, | ||
|
@@ -81,7 +146,7 @@ const AvailableNetworksv2 = ({ | |
screen: Routes.CURRENCY_SELECT_SCREEN, | ||
}); | ||
}, | ||
[asset, goBack, navigate, networks, updateInputCurrency] | ||
[asset, goBack, navigate, networks, swapsV2Enabled, swaps_v2, updateInputCurrency] | ||
); | ||
|
||
const handlePressContextMenu = useCallback( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,13 @@ function SwapActionButton({ asset, color: givenColor, inputType, label, fromDisc | |
const goToSwap = useCallback(() => { | ||
if (swapsV2Enabled || swaps_v2) { | ||
const chainId = ethereumUtils.getChainIdFromNetwork(asset.network); | ||
const userAsset = userAssetsStore.getState().userAssets.get(`${asset.address}_${chainId}`); | ||
const uniqueId = `${asset.address}_${chainId}`; | ||
const userAsset = userAssetsStore.getState().userAssets.get(uniqueId); | ||
|
||
const parsedAsset = parseSearchAsset({ | ||
assetWithPrice: { | ||
...asset, | ||
uniqueId, | ||
address: asset.address as AddressOrEth, | ||
type: asset.type as AssetType, | ||
chainId, | ||
|
@@ -52,6 +54,7 @@ function SwapActionButton({ asset, color: givenColor, inputType, label, fromDisc | |
}, | ||
searchAsset: { | ||
...asset, | ||
uniqueId, | ||
chainId, | ||
chainName: chainNameFromChainId(chainId), | ||
address: asset.address as AddressOrEth, | ||
|
@@ -74,6 +77,8 @@ function SwapActionButton({ asset, color: givenColor, inputType, label, fromDisc | |
.find(userAsset => userAsset.chainId === chainId && userAsset.address !== asset.address); | ||
if (largestBalanceSameChainUserAsset) { | ||
swapsStore.setState({ inputAsset: largestBalanceSameChainUserAsset }); | ||
} else { | ||
swapsStore.setState({ inputAsset: null }); | ||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was happening here too, so i added it here as well |
||
} | ||
swapsStore.setState({ outputAsset: parsedAsset }); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was
NaN
when no initial inputAsset was set.