-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.d.ts
221 lines (221 loc) · 7.17 KB
/
controller.d.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/// <reference types="node" />
import { LCDClientConfig } from '@terra-money/feather.js';
import { ExtensionOptions, LCDClient } from '@terra-money/feather.js';
import { ConnectedWallet, Connection, ConnectType, Installation, NetworkInfo, SignBytesResult, SignResult, TxResult, WalletStates } from '@nestwallet/wallet-types';
import { Observable } from 'rxjs';
import { ExtensionInfo } from './modules/extension-router/multiChannel';
import { ReadonlyWalletSession } from './modules/readonly-wallet';
import { WalletPlugin } from './modules/wallet-plugin/types';
import { WalletConnectControllerOptions } from './modules/walletconnect';
export interface WalletControllerOptions extends WalletConnectControllerOptions {
/**
* ⚠️ Don't hardcoding this, use getChain Options()
*
* fallback network if controller is not connected
*/
defaultNetwork: NetworkInfo;
/**
* ⚠️ Don't hardcoding this, use getChain Options()
*
* for walletconnect
*
* The network rules passed by the Terra Station Mobile are 0 is testnet, 1 is mainnet.
*
* Always set testnet for 0 and mainnet for 1.
*
* @example
* ```
* const mainnet: NetworkInfo = {
* name: 'mainnet',
* chainID: 'columbus-5',
* lcd: 'https://lcd.terra.dev',
* }
*
* const testnet: NetworkInfo = {
* name: 'testnet',
* chainID: 'bombay-12',
* lcd: 'https://bombay-lcd.terra.dev',
* }
*
* const walletConnectChainIds: Record<number, NetworkInfo> = {
* 0: testnet,
* 1: mainnet,
* }
*
* <WalletProvider walletConnectChainIds={walletConnectChainIds}>
* ```
*/
walletConnectChainIds: Record<number, NetworkInfo>;
/**
* run at executing the `connect(ConnectType.READONLY)`
*/
createReadonlyWalletSession?: (networks: NetworkInfo[]) => Promise<ReadonlyWalletSession | null>;
plugins?: WalletPlugin[];
/**
* run at executing the `connect()` - only used when does not input ConnectType
*/
selectConnection?: (connections: Connection[]) => Promise<[type: ConnectType, identifier: string | undefined] | null>;
/**
* run at executing the `connect(ConnectType.EXTENSION)`
* if user installed multiple wallets
*/
selectExtension?: (extensionInfos: ExtensionInfo[]) => Promise<ExtensionInfo | null>;
/**
* milliseconds to wait checking chrome extension is installed
*
* @default 1000 * 3 miliseconds
*/
waitingChromeExtensionInstallCheck?: number;
/**
* ⚠️ This API is an option for wallet developers. Please don't use dApp developers.
*
* @example
* ```
* <WalletProvider dangerously__chromeExtensionCompatibleBrowserCheck={(userAgent: string) => {
* return /MyWallet\//.test(userAgent);
* }}>
* ```
*/
dangerously__chromeExtensionCompatibleBrowserCheck?: (userAgent: string) => boolean;
}
export declare class WalletController {
readonly options: WalletControllerOptions;
private extension;
private walletConnect;
private readonlyWallet;
private plugin;
private _availableConnectTypes;
private _availableInstallTypes;
private _states;
private disableReadonlyWallet;
private disableExtension;
private disableWalletConnect;
private disableWalletPlugin;
private readonly _notConnected;
private readonly _initializing;
constructor(options: WalletControllerOptions);
/**
* Some mobile wallet emulates the behavior of chrome extension.
* It confirms that the current connection environment is such a wallet.
* (If you are running connect() by checking availableConnectType, you do not need to use this API.)
*
* @see Wallet#isChromeExtensionCompatibleBrowser
*/
isChromeExtensionCompatibleBrowser: () => boolean;
/**
* available connect types on the browser
*
* @see Wallet#availableConnectTypes
*/
availableConnectTypes: () => Observable<ConnectType[]>;
/**
* available connections includes identifier, name, icon
*
* @see Wallet#availableConnections
*/
availableConnections: () => Observable<Connection[]>;
/**
* available install types on the browser
*
* in this time, this only contains [ConnectType.EXTENSION]
*
* @see Wallet#availableInstallTypes
*/
availableInstallTypes: () => Observable<ConnectType[]>;
/**
* available installations includes identifier, name, icon, url
*
* @see Wallet#availableInstallations
*/
availableInstallations: () => Observable<Installation[]>;
/**
* @see Wallet#status
* @see Wallet#network
* @see Wallet#wallets
*/
states: () => Observable<WalletStates>;
/** get connectedWallet */
connectedWallet: () => Observable<ConnectedWallet | undefined>;
/** get lcdClient */
lcdClient: (lcdClientConfig: Record<string, LCDClientConfig>) => Observable<LCDClient>;
/**
* reload the connected wallet states
*
* in this time, this only work on the ConnectType.EXTENSION
*
* @see Wallet#recheckStatus
*/
refetchStates: () => void;
/**
* @deprecated Please use availableInstallations
*
* install for the connect type
*
* @see Wallet#install
*/
install: (type: ConnectType) => void;
/**
* connect to wallet
*
* @see Wallet#connect
*/
connect: (_type?: ConnectType, _identifier?: string) => Promise<void>;
/**
* manual connect to read only session
*
* @see Wallet#connectReadonly
*/
connectReadonly: (terraAddress: string, network: NetworkInfo) => void;
/** @see Wallet#disconnect */
disconnect: () => void;
/**
* @see Wallet#post
* @param tx
* @param terraAddress only available new extension
*/
post: (tx: ExtensionOptions, terraAddress?: string | undefined) => Promise<TxResult>;
/**
* @see Wallet#sign
* @param tx
* @param terraAddress only available new extension
*/
sign: (tx: ExtensionOptions, terraAddress?: string) => Promise<SignResult>;
/**
* @see Wallet#signBytes
* @param bytes
* @param terraAddress only available new extension
*/
signBytes: (bytes: Buffer, terraAddress?: string) => Promise<SignBytesResult>;
/**
* @see Wallet#hasCW20Tokens
* @param chainID
* @param tokenAddrs Token addresses
*/
hasCW20Tokens: (chainID: string, ...tokenAddrs: string[]) => Promise<{
[tokenAddr: string]: boolean;
}>;
/**
* @see Wallet#addCW20Tokens
* @param chainID
* @param tokenAddrs Token addresses
*/
addCW20Tokens: (chainID: string, ...tokenAddrs: string[]) => Promise<{
[tokenAddr: string]: boolean;
}>;
/**
* @see Wallet#hasNetwork
* @param network
*/
hasNetwork: (network: Omit<NetworkInfo, 'name'>) => Promise<boolean>;
/**
* @see Wallet#hasNetwork
* @param network
*/
addNetwork: (network: NetworkInfo) => Promise<boolean>;
private availableExtensionFeature;
private updateStates;
private enableReadonlyWallet;
private enableExtension;
private enableWalletConnect;
private enableWalletPlugin;
}