@@ -4,6 +4,7 @@ import type {
44 TokenBalance ,
55 TransactionListItem ,
66 UnspentWithUsd ,
7+ NftLog
78} from '@/types' ;
89import { type AddressStorage } from '@/cache/address/address-storage' ;
910import { stringify , parse } from '@/utils/json' ;
@@ -75,6 +76,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
7576 this . removeFromLocalStorage ( 'tokenInfo' ) ;
7677 this . removeFromLocalStorage ( 'tokenCreator' ) ;
7778 this . removeFromLocalStorage ( 'ens' ) ;
79+ this . removeFromLocalStorage ( 'nftLogs' ) ;
7880 }
7981
8082 // tokenTransfersTransactions is not cleared here (because we are not loading them from scratch later for optimization)
@@ -87,6 +89,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
8789 tokenInfo,
8890 tokenCreator,
8991 ens,
92+ nftLogs
9093 } = this . getAllCachedData ( ) ;
9194
9295 addresses . forEach ( ( address ) => {
@@ -97,6 +100,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
97100 delete tokenInfo [ address ] ;
98101 delete tokenCreator [ address ] ;
99102 delete ens [ address ] ;
103+ delete nftLogs [ address ] ;
100104 } ) ;
101105
102106 this . saveToLocalStorage ( 'tokens' , tokens ) ;
@@ -106,6 +110,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
106110 this . saveToLocalStorage ( 'tokenInfo' , tokenInfo ) ;
107111 this . saveToLocalStorage ( 'tokenCreator' , tokenCreator ) ;
108112 this . saveToLocalStorage ( 'ens' , ens ) ;
113+ this . saveToLocalStorage ( 'nftLogs' , nftLogs ) ;
109114 }
110115
111116 clearFavorites ( ) : void {
@@ -118,6 +123,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
118123 tokenInfo,
119124 tokenCreator,
120125 ens,
126+ nftLogs
121127 } = this . getAllCachedData ( ) ;
122128
123129 const favorites = this . getFavoriteAddresses ( ) ;
@@ -131,6 +137,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
131137 delete tokenInfo [ address ] ;
132138 delete tokenCreator [ address ] ;
133139 delete ens [ address ] ;
140+ delete nftLogs [ address ] ;
134141 } ) ;
135142
136143 this . saveToLocalStorage ( 'tokens' , tokens ) ;
@@ -141,6 +148,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
141148 this . saveToLocalStorage ( 'tokenInfo' , tokenInfo ) ;
142149 this . saveToLocalStorage ( 'tokenCreator' , tokenCreator ) ;
143150 this . saveToLocalStorage ( 'ens' , ens ) ;
151+ this . saveToLocalStorage ( 'nftLogs' , nftLogs ) ;
144152
145153 this . removeFromLocalStorage ( 'favoriteAddresses' ) ;
146154 }
@@ -155,6 +163,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
155163 tokenInfo,
156164 tokenCreator,
157165 ens,
166+ nftLogs
158167 } = this . getAllCachedData ( ) ;
159168
160169 return Array . from (
@@ -167,6 +176,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
167176 ...Object . keys ( tokenInfo ) ,
168177 ...Object . keys ( tokenCreator ) ,
169178 ...Object . keys ( ens ) ,
179+ ...Object . keys ( nftLogs )
170180 ] )
171181 ) ;
172182 }
@@ -180,6 +190,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
180190 const tokenInfo = this . getFromLocalStorage ( 'tokenInfo' ) ?? { } ;
181191 const tokenCreator = this . getFromLocalStorage ( 'tokenCreator' ) ?? { } ;
182192 const ens = this . getFromLocalStorage ( 'ens' ) ?? { } ;
193+ const nftLogs = this . getFromLocalStorage ( 'nftLogs' ) ?? { } ;
183194
184195 return {
185196 tokens,
@@ -190,6 +201,7 @@ export class LocalStorageAddressStorage implements AddressStorage {
190201 tokenInfo,
191202 tokenCreator,
192203 ens,
204+ nftLogs
193205 } ;
194206 } ;
195207
@@ -512,4 +524,32 @@ export class LocalStorageAddressStorage implements AddressStorage {
512524 const updated = cached . filter ( ( item : string ) => item !== addr ) ;
513525 this . saveToLocalStorage ( 'favoriteAddresses' , updated ) ;
514526 }
527+
528+ /**
529+ * NFT Cache
530+ */
531+
532+ addAllNftLogs ( logs : Map < string , NftLog [ ] > ) : void {
533+ this . addAllUnitToCache ( 'nftLogs' , logs ) ;
534+ }
535+
536+ getAllNftLogs ( ) : Map < string , NftLog [ ] > {
537+ return this . getAllCachedUnitAsMap ( 'nftLogs' ) ;
538+ }
539+
540+ getNftLogs ( address : string ) : NftLog [ ] {
541+ const cached = this . getFromLocalStorage ( 'nftLogs' ) ?? { } ;
542+ return cached [ address ] || [ ] ;
543+ }
544+
545+ addNftLogs ( address : string , logs : NftLog [ ] ) : void {
546+ const cached = this . getFromLocalStorage ( 'nftLogs' ) ?? { } ;
547+ cached [ address ] = logs ;
548+ this . saveToLocalStorage ( 'nftLogs' , cached ) ;
549+ }
550+
551+ hasNftLogs ( address : string ) : boolean {
552+ const cached = this . getFromLocalStorage ( 'nftLogs' ) ?? { } ;
553+ return address in cached ;
554+ }
515555}
0 commit comments