All files / app/utils disk-store.ts

74.07% Statements 20/27
100% Branches 2/2
12.5% Functions 1/8
68.42% Lines 13/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51    1x 1x 1x 1x 1x 1x                                   1x       1x       1x       1x       1x       1x       1x  
import { WalletType } from '../models/wallet-type';
 
enum StoreIndex {
  Salt = 'salt',
  EncryptedMnemonic = 'encryptedMnemonic',
  StxAddress = 'stxAddress',
  PublicKey = 'publicKey',
  WalletType = 'walletType',
}
 
interface SoftwareWallet {
  [StoreIndex.WalletType]: 'software';
  [StoreIndex.Salt]: string;
  [StoreIndex.EncryptedMnemonic]: string;
  [StoreIndex.StxAddress]: string;
}
 
interface LedgerWallet {
  [StoreIndex.WalletType]: 'ledger';
  [StoreIndex.StxAddress]: string;
  [StoreIndex.PublicKey]: string;
}
 
export type DiskStore = LedgerWallet | SoftwareWallet;
 
export const persistEncryptedMnemonic = async (encryptedMnemonic: string) => {
  return main.store.set(StoreIndex.EncryptedMnemonic, encryptedMnemonic);
};
 
export const persistStxAddress = async (stxAddress: string) => {
  return main.store.set(StoreIndex.StxAddress, stxAddress);
};
 
export const persistPublicKey = async (publicKey: string) => {
  return main.store.set(StoreIndex.PublicKey, publicKey);
};
 
export const persistSalt = async (salt: string) => {
  return main.store.set(StoreIndex.Salt, salt);
};
 
export const persistWalletType = async (walletType: WalletType) => {
  return main.store.set(StoreIndex.WalletType, walletType);
};
 
export const getInitialStateFromDisk = () => {
  return main.store.initialValue() as unknown as DiskStore;
};
 
export const clearDiskStorage = async () => main.store.clear();