license import { extensionBrowser } from '@algosigner/common/chrome' ; import { logging } from '@algosigner/common/logging' ; export class ExtensionStorage { public setStorage ( objectName , saveObject , callback ) { extensionBrowser . storage . local . set ( { [ objectName ] : saveObject } , ( ) => { const isSuccessful = ! extensionBrowser . runtime . lastError ; if ( ! isSuccessful ) { logging . log ( extensionBrowser . runtime . lastError && `Chrome error: ${ extensionBrowser . runtime . lastError . message }` ) ; } callback && callback ( isSuccessful ) ; } ) ; } public getStorage ( objectName , callback ) { extensionBrowser . storage . local . get ( [ objectName ] , ( result ) => { callback && callback ( result [ objectName ] ) ; } ) ; } public noAccountExistsCheck ( objectName , callback ) { extensionBrowser . storage . local . get ( [ objectName ] , function ( result ) { if ( result [ objectName ] ) { callback && callback ( true ) ; } else { callback && callback ( false ) ; } } ) ; } public clearStorageLocal ( callback ) { extensionBrowser . storage . local . clear ( ( ) => { if ( ! extensionBrowser . runtime . lastError ) { callback && callback ( true ) ; } else { callback && callback ( false ) ; } } ) ; } protected getStorageLocal ( callback ) { extensionBrowser . storage . local . get ( null , ( result ) => { if ( ! extensionBrowser . runtime . lastError ) { callback ( JSON . stringify ( result ) ) ; } } ) ; } } const extensionStorage = new ExtensionStorage ( ) ; export default extensionStorage ;