-
Notifications
You must be signed in to change notification settings - Fork 36
/
wallet-info-slice.ts
51 lines (50 loc) · 2.12 KB
/
wallet-info-slice.ts
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
import { WalletType } from '@cardano-sdk/web-extension';
import { BlockchainProviderSlice, SliceCreator, WalletInfoSlice } from '../types';
import { Wallet } from '@lace/cardano';
import { ObservableWalletState } from '@hooks/useWalletState';
/**
* has all wallet info related actions and states
*/
export const walletInfoSlice: SliceCreator<WalletInfoSlice & BlockchainProviderSlice, WalletInfoSlice> = ({
set,
get
}) => ({
// Wallet info and storage
setWalletInfo: (walletInfo) => set({ walletInfo }),
setManageAccountsWallet: (manageAccountsWallet) => set({ manageAccountsWallet }),
// Loaded wallet
manageAccountsWallet: undefined,
inMemoryWallet: undefined,
cardanoWallet: undefined,
walletState: undefined,
setWalletState: (walletState?: ObservableWalletState) => set({ walletState }),
walletManager: undefined,
initialHdDiscoveryCompleted: false,
isInMemoryWallet: undefined,
isHardwareWallet: undefined,
hasKeyMaterial: undefined,
walletType: undefined,
stayOnAllDonePage: false,
setAddressesDiscoveryCompleted: (addressesDiscoveryCompleted) =>
set({ initialHdDiscoveryCompleted: addressesDiscoveryCompleted }),
// eslint-disable-next-line unicorn/no-null
hdDiscoveryStatus: null,
setHdDiscoveryStatus: (hdDiscoveryStatus) => set({ hdDiscoveryStatus }),
setCardanoWallet: (wallet?: Wallet.CardanoWallet) =>
set({
inMemoryWallet: wallet?.wallet,
cardanoWallet: wallet,
walletType: wallet?.source.wallet.type,
isInMemoryWallet: wallet?.source.wallet.type === WalletType.InMemory,
isHardwareWallet: [WalletType.Ledger, WalletType.Trezor].includes(wallet?.source.wallet.type),
hasKeyMaterial:
wallet?.source.wallet.type === WalletType.InMemory &&
wallet?.source.wallet.encryptedSecrets.keyMaterial.length > 0
}),
setCurrentChain: (chain: Wallet.ChainName) => {
set({ currentChain: Wallet.Cardano.ChainIds[chain], environmentName: chain });
get().setBlockchainProvider(chain);
},
setDeletingWallet: (deletingWallet: boolean) => set({ deletingWallet }),
setStayOnAllDonePage: (stayOnAllDonePage: boolean) => set({ stayOnAllDonePage })
});