File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 44//
55import {
66 getChainRegistryByChainId ,
7+ getCorrespondingIbcAsset ,
78 namadaRegistryChainAssetsMapAtom ,
89} from "atoms/integrations" ;
910import BigNumber from "bignumber.js" ;
@@ -156,12 +157,8 @@ export const swapQuoteAtom = atomWithQuery((get) => {
156157 invariant ( sellAsset , "Sell asset not found" ) ;
157158 invariant ( buyAsset , "Buy asset not found" ) ;
158159
159- const fromOsmosis = osmosisAssets . find (
160- ( assets ) => assets . symbol === sellAsset . symbol
161- ) ;
162- const toOsmosis = osmosisAssets . find (
163- ( assets ) => assets . symbol === buyAsset . symbol
164- ) ;
160+ const fromOsmosis = getCorrespondingIbcAsset ( sellAsset , osmosisAssets ) ;
161+ const toOsmosis = getCorrespondingIbcAsset ( buyAsset , osmosisAssets ) ;
165162
166163 invariant ( fromOsmosis , "From asset is not found in Osmosis assets" ) ;
167164 invariant ( toOsmosis , "To asset is not found in Osmosis assets" ) ;
Original file line number Diff line number Diff line change @@ -263,3 +263,26 @@ export const getNamadaIbcInfo = (isHousefire: boolean): IBCInfo[] => {
263263
264264 return ibcInfo ;
265265} ;
266+
267+ export const getCounterpartyChainName = ( asset : Asset ) : string | undefined => {
268+ const chainName = asset . traces ?. find ( ( trace ) => trace . type === "ibc" )
269+ ?. counterparty . chain_name ;
270+
271+ return chainName ;
272+ } ;
273+
274+ export const getCorrespondingIbcAsset = (
275+ asset : NamadaAsset ,
276+ ibcAssets : Asset [ ]
277+ ) : Asset | undefined => {
278+ const assets = ibcAssets . filter ( ( assets ) => assets . symbol === asset . symbol ) ;
279+
280+ if ( assets . length === 1 ) {
281+ return assets [ 0 ] ;
282+ } else {
283+ const chainName = getCounterpartyChainName ( asset ) ;
284+ return assets . find (
285+ ( ibcAsset ) => getCounterpartyChainName ( ibcAsset ) === chainName
286+ ) ;
287+ }
288+ } ;
You can’t perform that action at this time.
0 commit comments