@@ -6,9 +6,9 @@ import type { PalletBagsListListBag } from '@polkadot/types/lookup';
66import type { BN } from '@polkadot/util' ;
77import type { BagInfo } from './types.js' ;
88
9- import { useEffect , useState } from 'react' ;
9+ import { useEffect , useMemo , useState } from 'react' ;
1010
11- import { createNamedHook , useCall , useMapKeys } from '@polkadot/react-hooks' ;
11+ import { createNamedHook , useApi , useCall , useCurrencyToVote , useMapKeys } from '@polkadot/react-hooks' ;
1212import { BN_ZERO } from '@polkadot/util' ;
1313
1414import useQueryModule from './useQueryModule.js' ;
@@ -54,13 +54,39 @@ function merge (prev: BagInfo[] | undefined, curr: BagInfo[]): BagInfo[] {
5454
5555function useBagsListImpl ( ) : BagInfo [ ] | undefined {
5656 const mod = useQueryModule ( ) ;
57+ const { api } = useApi ( ) ;
58+ const { toCurrency } = useCurrencyToVote ( ) ;
5759 const [ result , setResult ] = useState < BagInfo [ ] | undefined > ( ) ;
5860 const ids = useMapKeys ( mod . listBags , [ ] , KEY_OPTS ) ;
5961 const query = useCall ( ids && ids . length !== 0 && mod . listBags . multi , [ ids ] , MULTI_OPTS ) ;
6062
63+ const converted = useMemo (
64+ ( ) => {
65+ if ( ! query || query . length === 0 ) {
66+ return undefined ;
67+ }
68+
69+ // Westend Asset Hub uses SaturatingCurrencyToVote (no conversion needed)
70+ // See: https://github.com/paritytech/polkadot-sdk/pull/8307
71+ const chainName = api . runtimeChain . toString ( ) . toLowerCase ( ) ;
72+ const isWestendAssetHub = chainName . includes ( 'westend' ) && chainName . includes ( 'asset' ) ;
73+
74+ if ( isWestendAssetHub ) {
75+ return query ;
76+ }
77+
78+ return query . map ( ( bag ) => ( {
79+ ...bag ,
80+ bagLower : toCurrency ( bag . bagLower ) ,
81+ bagUpper : toCurrency ( bag . bagUpper )
82+ } ) ) ;
83+ } ,
84+ [ api . runtimeChain , query , toCurrency ]
85+ ) ;
86+
6187 useEffect ( ( ) : void => {
62- query && setResult ( ( prev ) => merge ( prev , query ) ) ;
63- } , [ query ] ) ;
88+ converted && setResult ( ( prev ) => merge ( prev , converted ) ) ;
89+ } , [ converted ] ) ;
6490
6591 return result ;
6692}
0 commit comments