import { NativeModules } from "react-native" ; import { Record , WalletConfig , WalletCredentials , WalletStorageRecord } from "./WalletInterface" ; const { ArnimaSdk } = NativeModules ; class WalletStorageService { async addWalletRecord ( config , credentials , type , id , value , tags ) { try { return await ArnimaSdk . addWalletRecord ( JSON . stringify ( config ) , JSON . stringify ( credentials ) , type , id , value , tags ) ; } catch ( error ) { console . log ( 'WalletStorageService - ' + type + ' - Add wallet record = ' , error ) ; throw error ; } } async updateWalletRecord ( config , credentials , type , id , value , tags ) { try { return await ArnimaSdk . updateWalletRecord ( JSON . stringify ( config ) , JSON . stringify ( credentials ) , type , id , value , tags ) ; } catch ( error ) { console . log ( 'WalletStorageService - ' + type + ' - Update wallet record = ' , error ) ; throw error ; } } async deleteWalletRecord ( config , credentials , type , id ) { try { return await ArnimaSdk . deleteWalletRecord ( JSON . stringify ( config ) , JSON . stringify ( credentials ) , type , id ) ; } catch ( error ) { console . log ( 'WalletStorageService - ' + type + ' - Delete wallet record = ' , error ) ; throw error ; } } async getWalletRecordFromQuery ( config , credentials , type , query ) { try { const queryResponse = await ArnimaSdk . getWalletRecordFromQuery ( JSON . stringify ( config ) , JSON . stringify ( credentials ) , type , query ) ; const walletRecord = JSON . parse ( queryResponse ) ; if ( walletRecord . records !== null ) { return JSON . parse ( walletRecord . records [ 0 ] . value ) ; } else { return [ ] ; } } catch ( error ) { console . log ( 'WalletStorageService - ' + type + ' - Get wallet record from query = ' , error ) ; throw error ; } } async getWalletRecordsFromQuery ( config , credentials , type , query ) { try { const queryResponse = await ArnimaSdk . getWalletRecordFromQuery ( JSON . stringify ( config ) , JSON . stringify ( credentials ) , type , query ) ; const walletRecord = JSON . parse ( queryResponse ) ; return walletRecord . records === null ? [ ] : walletRecord . records ; } catch ( error ) { console . log ( 'WalletStorageService - ' + type + ' - Get wallet records from query = ' , error ) ; throw error ; } } } export default new WalletStorageService ( ) ;