import { BurnerPluginContext , Plugin , Account , SendData } from '@burner-wallet/types' ; const STORAGE_KEY = 'burner-recent-accounts' ; export default class RecentAccountsPlugin implements Plugin { private addresses : string [ ] ; constructor ( ) { this . addresses = JSON . parse ( localStorage . getItem ( STORAGE_KEY ) || '[]' ) ; } initializePlugin ( pluginContext ) { pluginContext . onAccountSearch ( ( search ) => { const searchLowerCase = search . toLowerCase ( ) ; const accounts = this . addresses . filter ( ( address ) => address . indexOf ( searchLowerCase ) === 0 ) . map ( ( address ) : Account => ( { address , name : 'Recently sent' } ) ) ; return Promise . resolve ( accounts ) ; } ) ; pluginContext . onSent ( ( data ) => { if ( ! this . hasAddress ( data . to ) ) { this . addAddress ( data . to ) ; } } ) ; } hasAddress ( address ) { return this . addresses . indexOf ( address . toLowerCase ( ) ) !== - 1 ; } addAddress ( address ) { this . addresses . push ( address . toLowerCase ( ) ) ; this . save ( ) ; } save ( ) { localStorage . setItem ( STORAGE_KEY , JSON . stringify ( this . addresses ) ) ; } }