-
Notifications
You must be signed in to change notification settings - Fork 55
/
walletManager.types.ts
95 lines (83 loc) · 3.36 KB
/
walletManager.types.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { AnyWallet, WalletId } from './types';
import { Cardano } from '@cardano-sdk/core';
import { Observable } from 'rxjs';
import { ObservableWallet, storage } from '@cardano-sdk/wallet';
import { Witnesser } from '@cardano-sdk/key-management';
export interface WalletManagerProps {
name: string;
}
export interface WalletManagerActivateProps<P extends string | number = string, O = unknown> {
/** The walletId of the wallet to activate */
walletId: WalletId;
accountIndex?: number;
/** The chainId of the network to activate the wallet in */
chainId: Cardano.ChainId;
/**
* `provider` could be used to pass the necessary information to construct providers for different networks.
* Its value is passed to the {@link WalletFactory}, which is required to create {@link WalletManagerWorker}.
* The structure is in the hands of the user and depends on how the {@link WalletFactory} is implemented.
* An example of what a provider data could look like:
* ```ts
* props.provider = {
* type: ProviderType.CardanoServices,
* options: {cardanoServicesUrl: 'https://preview-api.mydomain.io'}
* }
* ```
* Another example using a mix of provider types:
* ```ts
* walletManager.activate({
* observableWalletName: 'MixedProvidersOnTestnet',
* provider: {
* options: {
* providers: [
* // WalletFactory will use this data to create a cardano-services-client ogmiosTxSubmitProvider
* { connectionConfig: ConnectionConfig, type: ProviderType.OgmiosTxSubmit },
* // WalletFactory will use this data to create the rest of the services
* { baseUrl: 'https://preview-api.mydomain.io', type: ProviderType.CardanoServices }
* ]
* },
* type: ProviderType.Mixed
* }
* })
* ```
*/
provider?: { type: P; options: O };
}
export interface WalletManagerApi {
activeWalletId$: Observable<WalletManagerActivateProps | null>;
/**
* Create and activate a new ObservableWallet.
* Reuses the store if the wallet was previously deactivated but not destroyed.
*/
activate(props: WalletManagerActivateProps, force?: boolean): Promise<void>;
/**
* Switches the network of the active wallet.
*
* @param id The chain id of the network to switch to.
*/
switchNetwork(id: Cardano.ChainId): Promise<void>;
/**
* Deactivate wallet. Wallet observable properties will emit only after a new wallet is {@link activate}ed.
* The wallet store will be reused if the wallet is reactivated.
*/
deactivate(): Promise<void>;
/**
* Destroy the specified store so that a future activation of the same wallet creates a new store.
*
* This method will destroy all stores for all accounts for the given ChainId.
*
* @param walletId The walletId of the wallet to destroy.
* @param chainId The chainId of the network to destroy the wallet in.
*/
destroyData(walletId: WalletId, chainId: Cardano.ChainId): Promise<void>;
}
export interface WalletFactory<WalletMetadata extends { name: string }, AccountMetadata extends { name: string }> {
create: (
props: WalletManagerActivateProps,
wallet: AnyWallet<WalletMetadata, AccountMetadata>,
dependencies: { witnesser: Witnesser; stores: storage.WalletStores }
) => Promise<ObservableWallet>;
}
export interface StoresFactory {
create: (props: { name: string }) => storage.WalletStores;
}