@@ -20,12 +20,10 @@ import { maspIndexerUrlAtom, rpcUrlAtom } from "atoms/settings";
2020import { queryDependentFn } from "atoms/utils" ;
2121import { isAxiosError } from "axios" ;
2222import BigNumber from "bignumber.js" ;
23- import * as E from "fp-ts/Either" ;
2423import { sequenceT } from "fp-ts/lib/Apply" ;
2524import { pipe } from "fp-ts/lib/function" ;
2625import * as O from "fp-ts/Option" ;
2726import invariant from "invariant" ;
28- import * as t from "io-ts" ;
2927import { atom , getDefaultStore } from "jotai" ;
3028import { atomWithQuery } from "jotai-tanstack-query" ;
3129import { atomWithStorage } from "jotai/utils" ;
@@ -111,43 +109,12 @@ export const viewingKeysAtom = atomWithQuery<
111109 } ;
112110} ) ;
113111
114- const NamadilloShieldedBalanceCodec = t . record (
115- t . string , // Address
116- t . array (
117- t . type ( {
118- tokenAddress : t . string ,
119- amount : t . string ,
120- } )
121- )
122- ) ;
123-
124112export const storageShieldedBalanceAtom = atomWithStorage <
125- Record < Address , { tokenAddress : Address ; amount : string } [ ] >
126- > (
127- "namadillo:shieldedBalance" ,
128- { } ,
129- {
130- // Invalidation function to ensure the stored data matches the codec
131- getItem ( key , initialValue ) {
132- const storedValue = localStorage . getItem ( key ) ;
133- const maybeValue = NamadilloShieldedBalanceCodec . decode (
134- JSON . parse ( storedValue ?? "{}" )
135- ) ;
136-
137- return E . isRight ( maybeValue ) ? maybeValue . right : initialValue ;
138- } ,
139- setItem ( key , value ) {
140- localStorage . setItem ( key , JSON . stringify ( value ) ) ;
141- } ,
142- removeItem ( key ) {
143- localStorage . removeItem ( key ) ;
144- } ,
145- }
146- ) ;
113+ Record < Address , { address : Address ; minDenomAmount : string } [ ] >
114+ > ( "namadillo:shieldedBalance" , { } ) ;
147115
148116export const shieldedSyncProgress = atom ( 0 ) ;
149117
150- // After changing the stored data type, change the version in the key
151118export const lastCompletedShieldedSyncAtom = atomWithStorage <
152119 Record < Address , Date | undefined >
153120> ( "namadillo:last-shielded-sync" , { } , undefined , { getOnInit : true } ) ;
@@ -165,13 +132,11 @@ export const shieldedBalanceAtom = atomWithQuery((get) => {
165132 const rpcUrl = get ( rpcUrlAtom ) ;
166133 const maspIndexerUrl = get ( maspIndexerUrlAtom ) ;
167134 const defaultAccount = get ( defaultAccountAtom ) ;
168- const assetsMapAtom = get ( namadaRegistryChainAssetsMapAtom ) ;
169135
170136 const [ viewingKey , allViewingKeys ] = viewingKeysQuery . data ?? [ ] ;
171137 const chainTokens = chainTokensQuery . data ?. map ( ( t ) => t . address ) ;
172138 const chainId = chainParametersQuery . data ?. chainId ;
173139 const namTokenAddress = namTokenAddressQuery . data ;
174- const assetsMap = assetsMapAtom . data ;
175140
176141 return {
177142 refetchInterval : enablePolling ? 1000 : false ,
@@ -183,8 +148,7 @@ export const shieldedBalanceAtom = atomWithQuery((get) => {
183148 ! chainTokens ||
184149 ! chainId ||
185150 ! namTokenAddress ||
186- ! rpcUrl ||
187- ! assetsMap
151+ ! rpcUrl
188152 ) {
189153 return [ ] ;
190154 }
@@ -204,24 +168,16 @@ export const shieldedBalanceAtom = atomWithQuery((get) => {
204168 chainTokens ,
205169 chainId
206170 ) ;
207- const shieldedBalance = response
208- // Filter out unknown assets
209- . filter ( ( [ address ] ) => address in assetsMap )
210- . map ( ( [ address , amount ] ) => {
211- const asset = assetsMap [ address ] ;
212- return {
213- tokenAddress : address ,
214- amount : toDisplayAmount ( asset , BigNumber ( amount ) ) ,
215- } ;
216- } ) ;
171+
172+ const shieldedBalance = response . map ( ( [ address , amount ] ) => ( {
173+ address,
174+ minDenomAmount : amount ,
175+ } ) ) ;
217176
218177 const storage = get ( storageShieldedBalanceAtom ) ;
219178 set ( storageShieldedBalanceAtom , {
220179 ...storage ,
221- [ viewingKey . key ] : shieldedBalance . map ( ( balance ) => ( {
222- ...balance ,
223- amount : balance . amount . toString ( ) ,
224- } ) ) ,
180+ [ viewingKey . key ] : shieldedBalance ,
225181 } ) ;
226182
227183 if ( defaultAccount . data ) {
@@ -242,7 +198,6 @@ export const shieldedBalanceAtom = atomWithQuery((get) => {
242198 chainTokensQuery ,
243199 chainParametersQuery ,
244200 namTokenAddressQuery ,
245- assetsMapAtom ,
246201 ] ) ,
247202 } ;
248203} ) ;
@@ -263,10 +218,8 @@ export const namadaShieldedAssetsAtom = atomWithQuery((get) => {
263218
264219 return mapNamadaAddressesToAssets ( {
265220 balances :
266- shieldedBalance ?. map ( ( i ) => ( {
267- ...i ,
268- amount : BigNumber ( i . amount ) ,
269- } ) ) ?? [ ] ,
221+ shieldedBalance ?. map ( ( i ) => ( { ...i , tokenAddress : i . address } ) ) ??
222+ [ ] ,
270223 assets : Object . values ( chainAssetsMap . data ) ,
271224 } ) ;
272225 } , [ viewingKeysQuery , chainTokensQuery , chainAssetsMap ] ) ,
0 commit comments