@txnlab/use-wallet 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/algosigner/client.d.ts +1 -1
- package/dist/cjs/clients/algosigner/types.d.ts +2 -1
- package/dist/cjs/clients/base/base.d.ts +4 -9
- package/dist/cjs/clients/defly/client.d.ts +1 -1
- package/dist/cjs/clients/defly/types.d.ts +2 -1
- package/dist/cjs/clients/exodus/client.d.ts +1 -1
- package/dist/cjs/clients/exodus/types.d.ts +2 -1
- package/dist/cjs/clients/kmd/client.d.ts +1 -1
- package/dist/cjs/clients/kmd/types.d.ts +2 -1
- package/dist/cjs/clients/myalgo/client.d.ts +1 -1
- package/dist/cjs/clients/myalgo/types.d.ts +2 -1
- package/dist/cjs/clients/pera/client.d.ts +1 -1
- package/dist/cjs/clients/pera/types.d.ts +2 -1
- package/dist/cjs/clients/walletconnect/client.d.ts +2 -3
- package/dist/cjs/clients/walletconnect/types.d.ts +2 -1
- package/dist/cjs/index.js +46 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/wallet.d.ts +6 -0
- package/dist/cjs/utils/clearAccounts.d.ts +2 -0
- package/dist/esm/clients/algosigner/client.d.ts +1 -1
- package/dist/esm/clients/algosigner/types.d.ts +2 -1
- package/dist/esm/clients/base/base.d.ts +4 -9
- package/dist/esm/clients/defly/client.d.ts +1 -1
- package/dist/esm/clients/defly/types.d.ts +2 -1
- package/dist/esm/clients/exodus/client.d.ts +1 -1
- package/dist/esm/clients/exodus/types.d.ts +2 -1
- package/dist/esm/clients/kmd/client.d.ts +1 -1
- package/dist/esm/clients/kmd/types.d.ts +2 -1
- package/dist/esm/clients/myalgo/client.d.ts +1 -1
- package/dist/esm/clients/myalgo/types.d.ts +2 -1
- package/dist/esm/clients/pera/client.d.ts +1 -1
- package/dist/esm/clients/pera/types.d.ts +2 -1
- package/dist/esm/clients/walletconnect/client.d.ts +2 -3
- package/dist/esm/clients/walletconnect/types.d.ts +2 -1
- package/dist/esm/index.js +46 -26
- package/dist/esm/types/wallet.d.ts +6 -0
- package/dist/esm/utils/clearAccounts.d.ts +2 -0
- package/dist/index.d.ts +24 -15
- package/package.json +1 -1
|
@@ -43,5 +43,11 @@ declare type ExtendValues<Type> = {
|
|
|
43
43
|
export declare type Wallet = ExtendValues<WalletProvider> & {
|
|
44
44
|
accounts: Account[];
|
|
45
45
|
};
|
|
46
|
+
export declare type Metadata = {
|
|
47
|
+
id: PROVIDER_ID;
|
|
48
|
+
name: string;
|
|
49
|
+
icon: string;
|
|
50
|
+
isWalletConnect: boolean;
|
|
51
|
+
};
|
|
46
52
|
export declare type WalletClient = BaseWallet;
|
|
47
53
|
export { PROVIDER_ID };
|
|
@@ -5,7 +5,7 @@ import type { AlgoSignerTransaction, AlgoSignerClientConstructor, InitParams } f
|
|
|
5
5
|
declare class AlgoSignerClient extends BaseWallet {
|
|
6
6
|
#private;
|
|
7
7
|
network: Network;
|
|
8
|
-
constructor({ client, algosdk, algodClient, network, }: AlgoSignerClientConstructor);
|
|
8
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: AlgoSignerClientConstructor);
|
|
9
9
|
static metadata: {
|
|
10
10
|
id: PROVIDER_ID;
|
|
11
11
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type _algosdk from "algosdk";
|
|
2
2
|
import { PROVIDER_ID } from "../../constants";
|
|
3
|
-
import type { AlgodClientOptions, Network } from "../../types";
|
|
3
|
+
import type { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
4
4
|
export declare type WindowExtended = {
|
|
5
5
|
AlgoSigner: AlgoSigner;
|
|
6
6
|
} & Window & typeof globalThis;
|
|
@@ -27,6 +27,7 @@ export declare type AlgoSigner = {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
export declare type AlgoSignerClientConstructor = {
|
|
30
|
+
metadata: Metadata;
|
|
30
31
|
client: AlgoSigner;
|
|
31
32
|
id: PROVIDER_ID;
|
|
32
33
|
algosdk: typeof _algosdk;
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import type _algosdk from "algosdk";
|
|
2
|
-
import {
|
|
3
|
-
import type { Asset, Wallet, AccountInfo, TransactionsArray } from "../../types";
|
|
2
|
+
import type { Asset, Wallet, AccountInfo, TransactionsArray, Metadata } from "../../types";
|
|
4
3
|
declare abstract class BaseClient {
|
|
5
4
|
algosdk: typeof _algosdk;
|
|
6
5
|
algodClient: _algosdk.Algodv2;
|
|
7
6
|
keepWCAlive: HTMLAudioElement;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name: string;
|
|
11
|
-
icon: string;
|
|
12
|
-
isWalletConnect: boolean;
|
|
13
|
-
};
|
|
7
|
+
metadata: Metadata;
|
|
8
|
+
static metadata: Metadata;
|
|
14
9
|
abstract connect(onDisconnect: () => void): Promise<Wallet>;
|
|
15
10
|
abstract disconnect(): Promise<void>;
|
|
16
11
|
abstract reconnect(onDisconnect: () => void): Promise<Wallet | null>;
|
|
17
12
|
abstract signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array>): Promise<Uint8Array[]>;
|
|
18
13
|
abstract signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
19
|
-
protected constructor(algosdk: typeof _algosdk, algodClient: _algosdk.Algodv2);
|
|
14
|
+
protected constructor(metadata: Metadata, algosdk: typeof _algosdk, algodClient: _algosdk.Algodv2);
|
|
20
15
|
healthCheck(): Promise<{}>;
|
|
21
16
|
getAccountInfo(address: string): Promise<AccountInfo>;
|
|
22
17
|
getAssets(address: string): Promise<Asset[]>;
|
|
@@ -7,7 +7,7 @@ import { DeflyTransaction, InitParams, DeflyWalletClientConstructor } from "./ty
|
|
|
7
7
|
declare class DeflyWalletClient extends BaseWallet {
|
|
8
8
|
#private;
|
|
9
9
|
network: Network;
|
|
10
|
-
constructor({ client, algosdk, algodClient, network, }: DeflyWalletClientConstructor);
|
|
10
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: DeflyWalletClientConstructor);
|
|
11
11
|
static metadata: {
|
|
12
12
|
id: PROVIDER_ID;
|
|
13
13
|
name: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transaction } from "algosdk";
|
|
2
|
-
import type { AlgodClientOptions, Network } from "../../types";
|
|
2
|
+
import type { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
3
3
|
import type { DeflyWalletConnect } from "@blockshake/defly-connect";
|
|
4
4
|
import type _algosdk from "algosdk";
|
|
5
5
|
export declare type ClientOptions = {
|
|
@@ -22,6 +22,7 @@ export declare type DeflyTransaction = {
|
|
|
22
22
|
signers?: string[];
|
|
23
23
|
};
|
|
24
24
|
export declare type DeflyWalletClientConstructor = {
|
|
25
|
+
metadata: Metadata;
|
|
25
26
|
client: DeflyWalletConnect;
|
|
26
27
|
algosdk: typeof _algosdk;
|
|
27
28
|
algodClient: _algosdk.Algodv2;
|
|
@@ -5,7 +5,7 @@ import { InitParams, ExodusClientConstructor } from "./types";
|
|
|
5
5
|
declare class ExodusClient extends BaseWallet {
|
|
6
6
|
#private;
|
|
7
7
|
network: Network;
|
|
8
|
-
constructor({ client, algosdk, algodClient, onlyIfTrusted, network, }: ExodusClientConstructor);
|
|
8
|
+
constructor({ metadata, client, algosdk, algodClient, onlyIfTrusted, network, }: ExodusClientConstructor);
|
|
9
9
|
static metadata: {
|
|
10
10
|
id: PROVIDER_ID;
|
|
11
11
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PROVIDER_ID } from "../../constants";
|
|
2
2
|
import type _algosdk from "algosdk";
|
|
3
|
-
import type { AlgodClientOptions, Network } from "../../types";
|
|
3
|
+
import type { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
4
4
|
export declare type ClientOptions = {
|
|
5
5
|
onlyIfTrusted: boolean;
|
|
6
6
|
};
|
|
@@ -25,6 +25,7 @@ export declare type Exodus = {
|
|
|
25
25
|
signTransaction(transactions: Bytes[]): Promise<Bytes[]>;
|
|
26
26
|
};
|
|
27
27
|
export declare type ExodusClientConstructor = {
|
|
28
|
+
metadata: Metadata;
|
|
28
29
|
client: Exodus;
|
|
29
30
|
id: PROVIDER_ID;
|
|
30
31
|
algosdk: typeof _algosdk;
|
|
@@ -7,7 +7,7 @@ declare class KMDWalletClient extends BaseWallet {
|
|
|
7
7
|
walletId: string;
|
|
8
8
|
id: PROVIDER_ID;
|
|
9
9
|
network: Network;
|
|
10
|
-
constructor({ client, id, wallet, password, algosdk, algodClient, network, }: KMDWalletClientConstructor);
|
|
10
|
+
constructor({ metadata, client, id, wallet, password, algosdk, algodClient, network, }: KMDWalletClientConstructor);
|
|
11
11
|
static metadata: {
|
|
12
12
|
id: PROVIDER_ID;
|
|
13
13
|
name: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type _algosdk from "algosdk";
|
|
2
|
-
import type { AlgodClientOptions, Network } from "../../types";
|
|
2
|
+
import type { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
3
3
|
import { PROVIDER_ID } from "../../constants";
|
|
4
4
|
export declare type ClientOptions = {
|
|
5
5
|
wallet: string;
|
|
@@ -22,6 +22,7 @@ export interface InitWalletHandle {
|
|
|
22
22
|
error?: boolean;
|
|
23
23
|
}
|
|
24
24
|
export declare type KMDWalletClientConstructor = {
|
|
25
|
+
metadata: Metadata;
|
|
25
26
|
client: _algosdk.Kmd;
|
|
26
27
|
id: PROVIDER_ID;
|
|
27
28
|
algosdk: typeof _algosdk;
|
|
@@ -9,7 +9,7 @@ import { MyAlgoWalletClientConstructor, InitParams } from "./types";
|
|
|
9
9
|
declare class MyAlgoWalletClient extends BaseWallet {
|
|
10
10
|
#private;
|
|
11
11
|
network: Network;
|
|
12
|
-
constructor({ client, algosdk, algodClient, network, }: MyAlgoWalletClientConstructor);
|
|
12
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: MyAlgoWalletClientConstructor);
|
|
13
13
|
static metadata: {
|
|
14
14
|
id: PROVIDER_ID;
|
|
15
15
|
name: string;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type _MyAlgoConnect from "@randlabs/myalgo-connect";
|
|
6
6
|
import type _algosdk from "algosdk";
|
|
7
|
-
import { AlgodClientOptions, Network } from "../../types";
|
|
7
|
+
import { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
8
8
|
export declare type MyAlgoWalletClientConstructor = {
|
|
9
|
+
metadata: Metadata;
|
|
9
10
|
client: _MyAlgoConnect;
|
|
10
11
|
algosdk: typeof _algosdk;
|
|
11
12
|
algodClient: _algosdk.Algodv2;
|
|
@@ -5,7 +5,7 @@ import { PeraTransaction, PeraWalletClientConstructor, InitParams } from "./type
|
|
|
5
5
|
declare class PeraWalletClient extends BaseWallet {
|
|
6
6
|
#private;
|
|
7
7
|
network: Network;
|
|
8
|
-
constructor({ client, algosdk, algodClient, network, }: PeraWalletClientConstructor);
|
|
8
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: PeraWalletClientConstructor);
|
|
9
9
|
static metadata: {
|
|
10
10
|
id: PROVIDER_ID;
|
|
11
11
|
name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type _algosdk from "algosdk";
|
|
2
2
|
import type { PeraWalletConnect } from "@perawallet/connect";
|
|
3
3
|
import type { Transaction } from "algosdk";
|
|
4
|
-
import type { AlgodClientOptions, Network } from "../../types";
|
|
4
|
+
import type { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
5
5
|
export declare type ClientOptions = {
|
|
6
6
|
bridge?: string;
|
|
7
7
|
deep_link?: string;
|
|
@@ -22,6 +22,7 @@ export interface PeraTransaction {
|
|
|
22
22
|
signers?: string[];
|
|
23
23
|
}
|
|
24
24
|
export declare type PeraWalletClientConstructor = {
|
|
25
|
+
metadata: Metadata;
|
|
25
26
|
client: PeraWalletConnect;
|
|
26
27
|
algosdk: typeof _algosdk;
|
|
27
28
|
algodClient: _algosdk.Algodv2;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { Wallet } from "../../types";
|
|
2
1
|
import { PROVIDER_ID } from "../../constants";
|
|
3
2
|
import BaseWallet from "../base";
|
|
4
|
-
import { TransactionsArray, Network } from "../../types";
|
|
3
|
+
import { Wallet, TransactionsArray, Network } from "../../types";
|
|
5
4
|
import { WalletConnectClientConstructor, InitParams, WalletConnectTransaction } from "./types";
|
|
6
5
|
declare class WalletConnectClient extends BaseWallet {
|
|
7
6
|
#private;
|
|
8
7
|
network: Network;
|
|
9
|
-
constructor({ client, algosdk, algodClient, network, }: WalletConnectClientConstructor);
|
|
8
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: WalletConnectClientConstructor);
|
|
10
9
|
static metadata: {
|
|
11
10
|
id: PROVIDER_ID;
|
|
12
11
|
name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type _algosdk from "algosdk";
|
|
2
2
|
import type WalletConnect from "@walletconnect/client";
|
|
3
3
|
import QRCodeModal from "algorand-walletconnect-qrcode-modal";
|
|
4
|
-
import type { AlgodClientOptions, Network } from "../../types";
|
|
4
|
+
import type { AlgodClientOptions, Network, Metadata } from "../../types";
|
|
5
5
|
export interface IClientMeta {
|
|
6
6
|
description: string;
|
|
7
7
|
url: string;
|
|
@@ -47,6 +47,7 @@ export declare type InitParams = {
|
|
|
47
47
|
network?: Network;
|
|
48
48
|
};
|
|
49
49
|
export declare type WalletConnectClientConstructor = {
|
|
50
|
+
metadata: Metadata;
|
|
50
51
|
client: WalletConnect;
|
|
51
52
|
algosdk: typeof _algosdk;
|
|
52
53
|
algodClient: _algosdk.Algodv2;
|
package/dist/esm/index.js
CHANGED
|
@@ -939,11 +939,13 @@ class BaseClient {
|
|
|
939
939
|
algosdk;
|
|
940
940
|
algodClient;
|
|
941
941
|
keepWCAlive;
|
|
942
|
+
metadata;
|
|
942
943
|
static metadata;
|
|
943
|
-
constructor(algosdk, algodClient) {
|
|
944
|
+
constructor(metadata, algosdk, algodClient) {
|
|
944
945
|
this.algosdk = algosdk;
|
|
945
946
|
this.algodClient = algodClient;
|
|
946
947
|
this.keepWCAlive = new Audio();
|
|
948
|
+
this.metadata = metadata;
|
|
947
949
|
}
|
|
948
950
|
async healthCheck() {
|
|
949
951
|
return await this.algodClient.healthCheck().do();
|
|
@@ -1061,10 +1063,11 @@ const ICON$6 = "data:image/svg+xml;base64," +
|
|
|
1061
1063
|
class PeraWalletClient extends BaseClient {
|
|
1062
1064
|
#client;
|
|
1063
1065
|
network;
|
|
1064
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1065
|
-
super(algosdk, algodClient);
|
|
1066
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1067
|
+
super(metadata, algosdk, algodClient);
|
|
1066
1068
|
this.#client = client;
|
|
1067
1069
|
this.network = network;
|
|
1070
|
+
this.metadata = PeraWalletClient.metadata;
|
|
1068
1071
|
}
|
|
1069
1072
|
static metadata = {
|
|
1070
1073
|
id: PROVIDER_ID.PERA,
|
|
@@ -1081,6 +1084,7 @@ class PeraWalletClient extends BaseClient {
|
|
|
1081
1084
|
...(clientOptions ? clientOptions : { shouldShowSignTxnToast: false }),
|
|
1082
1085
|
});
|
|
1083
1086
|
return new PeraWalletClient({
|
|
1087
|
+
metadata: PeraWalletClient.metadata,
|
|
1084
1088
|
client: peraWallet,
|
|
1085
1089
|
algosdk,
|
|
1086
1090
|
algodClient,
|
|
@@ -1110,8 +1114,10 @@ class PeraWalletClient extends BaseClient {
|
|
|
1110
1114
|
}
|
|
1111
1115
|
async reconnect(onDisconnect) {
|
|
1112
1116
|
const accounts = await this.#client.reconnectSession().catch(console.info);
|
|
1117
|
+
console.log("accounts?", accounts);
|
|
1113
1118
|
this.#client.connector?.on("disconnect", onDisconnect);
|
|
1114
1119
|
if (!accounts) {
|
|
1120
|
+
onDisconnect();
|
|
1115
1121
|
return null;
|
|
1116
1122
|
}
|
|
1117
1123
|
return {
|
|
@@ -1212,10 +1218,11 @@ const ICON$5 = "data:image/svg+xml;base64," +
|
|
|
1212
1218
|
class MyAlgoWalletClient extends BaseClient {
|
|
1213
1219
|
#client;
|
|
1214
1220
|
network;
|
|
1215
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1216
|
-
super(algosdk, algodClient);
|
|
1221
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1222
|
+
super(metadata, algosdk, algodClient);
|
|
1217
1223
|
this.#client = client;
|
|
1218
1224
|
this.network = network;
|
|
1225
|
+
this.metadata = MyAlgoWalletClient.metadata;
|
|
1219
1226
|
}
|
|
1220
1227
|
static metadata = {
|
|
1221
1228
|
id: PROVIDER_ID.MYALGO,
|
|
@@ -1232,6 +1239,7 @@ class MyAlgoWalletClient extends BaseClient {
|
|
|
1232
1239
|
...(clientOptions ? clientOptions : { disableLedgerNano: false }),
|
|
1233
1240
|
});
|
|
1234
1241
|
return new MyAlgoWalletClient({
|
|
1242
|
+
metadata: MyAlgoWalletClient.metadata,
|
|
1235
1243
|
client: myAlgo,
|
|
1236
1244
|
algosdk: algosdk,
|
|
1237
1245
|
algodClient: algodClient,
|
|
@@ -1326,10 +1334,11 @@ const ICON$4 = "data:image/svg+xml;base64," +
|
|
|
1326
1334
|
class DeflyWalletClient extends BaseClient {
|
|
1327
1335
|
#client;
|
|
1328
1336
|
network;
|
|
1329
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1330
|
-
super(algosdk, algodClient);
|
|
1337
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1338
|
+
super(metadata, algosdk, algodClient);
|
|
1331
1339
|
this.#client = client;
|
|
1332
1340
|
this.network = network;
|
|
1341
|
+
this.metadata = DeflyWalletClient.metadata;
|
|
1333
1342
|
}
|
|
1334
1343
|
static metadata = {
|
|
1335
1344
|
id: PROVIDER_ID.DEFLY,
|
|
@@ -1347,6 +1356,7 @@ class DeflyWalletClient extends BaseClient {
|
|
|
1347
1356
|
...(clientOptions ? clientOptions : { shouldShowSignTxnToast: false }),
|
|
1348
1357
|
});
|
|
1349
1358
|
return new DeflyWalletClient({
|
|
1359
|
+
metadata: DeflyWalletClient.metadata,
|
|
1350
1360
|
client: deflyWallet,
|
|
1351
1361
|
algosdk,
|
|
1352
1362
|
algodClient,
|
|
@@ -1475,11 +1485,12 @@ class ExodusClient extends BaseClient {
|
|
|
1475
1485
|
#client;
|
|
1476
1486
|
#onlyIfTrusted;
|
|
1477
1487
|
network;
|
|
1478
|
-
constructor({ client, algosdk, algodClient, onlyIfTrusted, network, }) {
|
|
1479
|
-
super(algosdk, algodClient);
|
|
1488
|
+
constructor({ metadata, client, algosdk, algodClient, onlyIfTrusted, network, }) {
|
|
1489
|
+
super(metadata, algosdk, algodClient);
|
|
1480
1490
|
this.#client = client;
|
|
1481
1491
|
this.#onlyIfTrusted = onlyIfTrusted;
|
|
1482
1492
|
this.network = network;
|
|
1493
|
+
this.metadata = ExodusClient.metadata;
|
|
1483
1494
|
}
|
|
1484
1495
|
static metadata = {
|
|
1485
1496
|
id: PROVIDER_ID.EXODUS,
|
|
@@ -1497,6 +1508,7 @@ class ExodusClient extends BaseClient {
|
|
|
1497
1508
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1498
1509
|
const exodus = window.exodus.algorand;
|
|
1499
1510
|
return new ExodusClient({
|
|
1511
|
+
metadata: ExodusClient.metadata,
|
|
1500
1512
|
id: PROVIDER_ID.EXODUS,
|
|
1501
1513
|
client: exodus,
|
|
1502
1514
|
algosdk: algosdk,
|
|
@@ -1616,8 +1628,8 @@ const getNetwork = (network) => {
|
|
|
1616
1628
|
class AlgoSignerClient extends BaseClient {
|
|
1617
1629
|
#client;
|
|
1618
1630
|
network;
|
|
1619
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1620
|
-
super(algosdk, algodClient);
|
|
1631
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1632
|
+
super(metadata, algosdk, algodClient);
|
|
1621
1633
|
this.#client = client;
|
|
1622
1634
|
this.network = network;
|
|
1623
1635
|
}
|
|
@@ -1637,6 +1649,7 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1637
1649
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1638
1650
|
const algosigner = window.AlgoSigner;
|
|
1639
1651
|
return new AlgoSignerClient({
|
|
1652
|
+
metadata: AlgoSignerClient.metadata,
|
|
1640
1653
|
id: PROVIDER_ID.ALGOSIGNER,
|
|
1641
1654
|
client: algosigner,
|
|
1642
1655
|
algosdk: algosdk,
|
|
@@ -1756,10 +1769,11 @@ const DEFAULT_NETWORK = "mainnet";
|
|
|
1756
1769
|
class WalletConnectClient extends BaseClient {
|
|
1757
1770
|
#client;
|
|
1758
1771
|
network;
|
|
1759
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1760
|
-
super(algosdk, algodClient);
|
|
1772
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1773
|
+
super(metadata, algosdk, algodClient);
|
|
1761
1774
|
this.#client = client;
|
|
1762
1775
|
this.network = network;
|
|
1776
|
+
this.metadata = WalletConnectClient.metadata;
|
|
1763
1777
|
}
|
|
1764
1778
|
static metadata = {
|
|
1765
1779
|
id: PROVIDER_ID.WALLETCONNECT,
|
|
@@ -1783,6 +1797,7 @@ class WalletConnectClient extends BaseClient {
|
|
|
1783
1797
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1784
1798
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1785
1799
|
const initWallet = {
|
|
1800
|
+
metadata: WalletConnectClient.metadata,
|
|
1786
1801
|
client: walletConnect,
|
|
1787
1802
|
algosdk: algosdk,
|
|
1788
1803
|
algodClient: algodClient,
|
|
@@ -1950,14 +1965,15 @@ class KMDWalletClient extends BaseClient {
|
|
|
1950
1965
|
walletId;
|
|
1951
1966
|
id;
|
|
1952
1967
|
network;
|
|
1953
|
-
constructor({ client, id, wallet, password, algosdk, algodClient, network, }) {
|
|
1954
|
-
super(algosdk, algodClient);
|
|
1968
|
+
constructor({ metadata, client, id, wallet, password, algosdk, algodClient, network, }) {
|
|
1969
|
+
super(metadata, algosdk, algodClient);
|
|
1955
1970
|
this.#client = client;
|
|
1956
1971
|
this.#wallet = wallet;
|
|
1957
1972
|
this.#password = password;
|
|
1958
1973
|
this.id = id;
|
|
1959
1974
|
this.walletId = "";
|
|
1960
1975
|
this.network = network;
|
|
1976
|
+
this.metadata = KMDWalletClient.metadata;
|
|
1961
1977
|
}
|
|
1962
1978
|
static metadata = {
|
|
1963
1979
|
id: PROVIDER_ID.KMD,
|
|
@@ -1967,11 +1983,12 @@ class KMDWalletClient extends BaseClient {
|
|
|
1967
1983
|
};
|
|
1968
1984
|
static async init({ clientOptions, algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1, }) {
|
|
1969
1985
|
try {
|
|
1970
|
-
const { token = "a".repeat(64), host = "http://localhost", port = "4002", wallet = "", password = "", } = clientOptions || {};
|
|
1986
|
+
const { token = "a".repeat(64), host = "http://localhost", port = "4002", wallet = "unencrypted-default-wallet", password = "", } = clientOptions || {};
|
|
1971
1987
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1972
1988
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1973
1989
|
const kmdClient = new algosdk.Kmd(token, host, port);
|
|
1974
1990
|
return new KMDWalletClient({
|
|
1991
|
+
metadata: KMDWalletClient.metadata,
|
|
1975
1992
|
id: PROVIDER_ID.KMD,
|
|
1976
1993
|
password,
|
|
1977
1994
|
wallet,
|
|
@@ -1997,10 +2014,7 @@ class KMDWalletClient extends BaseClient {
|
|
|
1997
2014
|
return;
|
|
1998
2015
|
}
|
|
1999
2016
|
async reconnect() {
|
|
2000
|
-
return
|
|
2001
|
-
...KMDWalletClient.metadata,
|
|
2002
|
-
accounts: await this.listAccounts(this.#wallet, this.#password || (await this.requestPassword())),
|
|
2003
|
-
};
|
|
2017
|
+
return null;
|
|
2004
2018
|
}
|
|
2005
2019
|
async requestPassword() {
|
|
2006
2020
|
// TODO: store it locally?
|
|
@@ -2098,6 +2112,13 @@ var allClients = {
|
|
|
2098
2112
|
[KMDWalletClient.metadata.id]: KMDWalletClient,
|
|
2099
2113
|
};
|
|
2100
2114
|
|
|
2115
|
+
const clearActiveAccount = useWalletStore.getState().clearActiveAccount;
|
|
2116
|
+
const removeAccounts = useWalletStore.getState().removeAccounts;
|
|
2117
|
+
const clearAccounts = (id) => {
|
|
2118
|
+
clearActiveAccount(id);
|
|
2119
|
+
removeAccounts(id);
|
|
2120
|
+
};
|
|
2121
|
+
|
|
2101
2122
|
function shallow(objA, objB) {
|
|
2102
2123
|
if (Object.is(objA, objB)) {
|
|
2103
2124
|
return true;
|
|
@@ -2119,7 +2140,7 @@ function shallow(objA, objB) {
|
|
|
2119
2140
|
|
|
2120
2141
|
function useWallet() {
|
|
2121
2142
|
const clients = useContext(ClientContext);
|
|
2122
|
-
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount,
|
|
2143
|
+
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount, addAccounts, } = useWalletStore(walletStoreSelector, shallow);
|
|
2123
2144
|
const getAccountsByProvider = (id) => {
|
|
2124
2145
|
return connectedAccounts.filter((account) => account.providerId === id);
|
|
2125
2146
|
};
|
|
@@ -2181,7 +2202,7 @@ function useWallet() {
|
|
|
2181
2202
|
try {
|
|
2182
2203
|
await disconnectWCSessions(id);
|
|
2183
2204
|
const walletClient = await getClient(id);
|
|
2184
|
-
const walletInfo = await walletClient?.connect(() =>
|
|
2205
|
+
const walletInfo = await walletClient?.connect(() => clearAccounts(id));
|
|
2185
2206
|
if (!walletInfo || !walletInfo.accounts.length) {
|
|
2186
2207
|
throw new Error("Failed to connect " + id);
|
|
2187
2208
|
}
|
|
@@ -2195,7 +2216,7 @@ function useWallet() {
|
|
|
2195
2216
|
const reconnect = async (id) => {
|
|
2196
2217
|
try {
|
|
2197
2218
|
const walletClient = await getClient(id);
|
|
2198
|
-
const walletInfo = await walletClient?.reconnect(() =>
|
|
2219
|
+
const walletInfo = await walletClient?.reconnect(() => clearAccounts(id));
|
|
2199
2220
|
if (walletInfo && walletInfo.accounts.length) {
|
|
2200
2221
|
addAccounts(walletInfo.accounts);
|
|
2201
2222
|
}
|
|
@@ -2214,8 +2235,7 @@ function useWallet() {
|
|
|
2214
2235
|
console.error(e);
|
|
2215
2236
|
}
|
|
2216
2237
|
finally {
|
|
2217
|
-
|
|
2218
|
-
removeAccounts(id);
|
|
2238
|
+
clearAccounts(id);
|
|
2219
2239
|
}
|
|
2220
2240
|
};
|
|
2221
2241
|
const setActive = async (id) => {
|
|
@@ -2325,7 +2345,7 @@ const reconnectProviders = async (providers) => {
|
|
|
2325
2345
|
const clients = Object.values(providers);
|
|
2326
2346
|
for (const client of clients) {
|
|
2327
2347
|
const c = await client;
|
|
2328
|
-
c?.reconnect(c?.
|
|
2348
|
+
c?.reconnect(() => clearAccounts(c?.metadata.id));
|
|
2329
2349
|
}
|
|
2330
2350
|
}
|
|
2331
2351
|
catch (e) {
|
|
@@ -43,5 +43,11 @@ declare type ExtendValues<Type> = {
|
|
|
43
43
|
export declare type Wallet = ExtendValues<WalletProvider> & {
|
|
44
44
|
accounts: Account[];
|
|
45
45
|
};
|
|
46
|
+
export declare type Metadata = {
|
|
47
|
+
id: PROVIDER_ID;
|
|
48
|
+
name: string;
|
|
49
|
+
icon: string;
|
|
50
|
+
isWalletConnect: boolean;
|
|
51
|
+
};
|
|
46
52
|
export declare type WalletClient = BaseWallet;
|
|
47
53
|
export { PROVIDER_ID };
|
package/dist/index.d.ts
CHANGED
|
@@ -78,18 +78,14 @@ declare abstract class BaseClient {
|
|
|
78
78
|
algosdk: typeof _algosdk;
|
|
79
79
|
algodClient: _algosdk.Algodv2;
|
|
80
80
|
keepWCAlive: HTMLAudioElement;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
name: string;
|
|
84
|
-
icon: string;
|
|
85
|
-
isWalletConnect: boolean;
|
|
86
|
-
};
|
|
81
|
+
metadata: Metadata;
|
|
82
|
+
static metadata: Metadata;
|
|
87
83
|
abstract connect(onDisconnect: () => void): Promise<Wallet>;
|
|
88
84
|
abstract disconnect(): Promise<void>;
|
|
89
85
|
abstract reconnect(onDisconnect: () => void): Promise<Wallet | null>;
|
|
90
86
|
abstract signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array>): Promise<Uint8Array[]>;
|
|
91
87
|
abstract signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
92
|
-
protected constructor(algosdk: typeof _algosdk, algodClient: _algosdk.Algodv2);
|
|
88
|
+
protected constructor(metadata: Metadata, algosdk: typeof _algosdk, algodClient: _algosdk.Algodv2);
|
|
93
89
|
healthCheck(): Promise<{}>;
|
|
94
90
|
getAccountInfo(address: string): Promise<AccountInfo>;
|
|
95
91
|
getAssets(address: string): Promise<Asset[]>;
|
|
@@ -164,6 +160,12 @@ declare type ExtendValues<Type> = {
|
|
|
164
160
|
declare type Wallet = ExtendValues<WalletProvider> & {
|
|
165
161
|
accounts: Account[];
|
|
166
162
|
};
|
|
163
|
+
declare type Metadata = {
|
|
164
|
+
id: PROVIDER_ID;
|
|
165
|
+
name: string;
|
|
166
|
+
icon: string;
|
|
167
|
+
isWalletConnect: boolean;
|
|
168
|
+
};
|
|
167
169
|
declare type WalletClient = BaseClient;
|
|
168
170
|
|
|
169
171
|
declare function useWallet(): {
|
|
@@ -363,6 +365,7 @@ interface PeraTransaction {
|
|
|
363
365
|
signers?: string[];
|
|
364
366
|
}
|
|
365
367
|
declare type PeraWalletClientConstructor = {
|
|
368
|
+
metadata: Metadata;
|
|
366
369
|
client: PeraWalletConnect;
|
|
367
370
|
algosdk: typeof _algosdk;
|
|
368
371
|
algodClient: _algosdk.Algodv2;
|
|
@@ -379,7 +382,7 @@ declare type InitParams$6 = {
|
|
|
379
382
|
declare class PeraWalletClient extends BaseClient {
|
|
380
383
|
#private;
|
|
381
384
|
network: Network;
|
|
382
|
-
constructor({ client, algosdk, algodClient, network, }: PeraWalletClientConstructor);
|
|
385
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: PeraWalletClientConstructor);
|
|
383
386
|
static metadata: {
|
|
384
387
|
id: PROVIDER_ID;
|
|
385
388
|
name: string;
|
|
@@ -413,6 +416,7 @@ declare class PeraWalletClient extends BaseClient {
|
|
|
413
416
|
*/
|
|
414
417
|
|
|
415
418
|
declare type MyAlgoWalletClientConstructor = {
|
|
419
|
+
metadata: Metadata;
|
|
416
420
|
client: _MyAlgoConnect;
|
|
417
421
|
algosdk: typeof _algosdk;
|
|
418
422
|
algodClient: _algosdk.Algodv2;
|
|
@@ -437,7 +441,7 @@ declare type InitParams$5 = {
|
|
|
437
441
|
declare class MyAlgoWalletClient extends BaseClient {
|
|
438
442
|
#private;
|
|
439
443
|
network: Network;
|
|
440
|
-
constructor({ client, algosdk, algodClient, network, }: MyAlgoWalletClientConstructor);
|
|
444
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: MyAlgoWalletClientConstructor);
|
|
441
445
|
static metadata: {
|
|
442
446
|
id: PROVIDER_ID;
|
|
443
447
|
name: string;
|
|
@@ -483,6 +487,7 @@ declare type DeflyTransaction = {
|
|
|
483
487
|
signers?: string[];
|
|
484
488
|
};
|
|
485
489
|
declare type DeflyWalletClientConstructor = {
|
|
490
|
+
metadata: Metadata;
|
|
486
491
|
client: DeflyWalletConnect;
|
|
487
492
|
algosdk: typeof _algosdk;
|
|
488
493
|
algodClient: _algosdk.Algodv2;
|
|
@@ -499,7 +504,7 @@ declare type InitParams$4 = {
|
|
|
499
504
|
declare class DeflyWalletClient extends BaseClient {
|
|
500
505
|
#private;
|
|
501
506
|
network: Network;
|
|
502
|
-
constructor({ client, algosdk, algodClient, network, }: DeflyWalletClientConstructor);
|
|
507
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: DeflyWalletClientConstructor);
|
|
503
508
|
static metadata: {
|
|
504
509
|
id: PROVIDER_ID;
|
|
505
510
|
name: string;
|
|
@@ -546,6 +551,7 @@ declare type Exodus = {
|
|
|
546
551
|
signTransaction(transactions: Bytes[]): Promise<Bytes[]>;
|
|
547
552
|
};
|
|
548
553
|
declare type ExodusClientConstructor = {
|
|
554
|
+
metadata: Metadata;
|
|
549
555
|
client: Exodus;
|
|
550
556
|
id: PROVIDER_ID;
|
|
551
557
|
algosdk: typeof _algosdk;
|
|
@@ -563,7 +569,7 @@ declare type InitParams$3 = {
|
|
|
563
569
|
declare class ExodusClient extends BaseClient {
|
|
564
570
|
#private;
|
|
565
571
|
network: Network;
|
|
566
|
-
constructor({ client, algosdk, algodClient, onlyIfTrusted, network, }: ExodusClientConstructor);
|
|
572
|
+
constructor({ metadata, client, algosdk, algodClient, onlyIfTrusted, network, }: ExodusClientConstructor);
|
|
567
573
|
static metadata: {
|
|
568
574
|
id: PROVIDER_ID;
|
|
569
575
|
name: string;
|
|
@@ -612,6 +618,7 @@ declare type AlgoSigner = {
|
|
|
612
618
|
};
|
|
613
619
|
};
|
|
614
620
|
declare type AlgoSignerClientConstructor = {
|
|
621
|
+
metadata: Metadata;
|
|
615
622
|
client: AlgoSigner;
|
|
616
623
|
id: PROVIDER_ID;
|
|
617
624
|
algosdk: typeof _algosdk;
|
|
@@ -627,7 +634,7 @@ declare type InitParams$2 = {
|
|
|
627
634
|
declare class AlgoSignerClient extends BaseClient {
|
|
628
635
|
#private;
|
|
629
636
|
network: Network;
|
|
630
|
-
constructor({ client, algosdk, algodClient, network, }: AlgoSignerClientConstructor);
|
|
637
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: AlgoSignerClientConstructor);
|
|
631
638
|
static metadata: {
|
|
632
639
|
id: PROVIDER_ID;
|
|
633
640
|
name: string;
|
|
@@ -700,6 +707,7 @@ declare type InitParams$1 = {
|
|
|
700
707
|
network?: Network;
|
|
701
708
|
};
|
|
702
709
|
declare type WalletConnectClientConstructor = {
|
|
710
|
+
metadata: Metadata;
|
|
703
711
|
client: WalletConnect;
|
|
704
712
|
algosdk: typeof _algosdk;
|
|
705
713
|
algodClient: _algosdk.Algodv2;
|
|
@@ -709,7 +717,7 @@ declare type WalletConnectClientConstructor = {
|
|
|
709
717
|
declare class WalletConnectClient extends BaseClient {
|
|
710
718
|
#private;
|
|
711
719
|
network: Network;
|
|
712
|
-
constructor({ client, algosdk, algodClient, network, }: WalletConnectClientConstructor);
|
|
720
|
+
constructor({ metadata, client, algosdk, algodClient, network, }: WalletConnectClientConstructor);
|
|
713
721
|
static metadata: {
|
|
714
722
|
id: PROVIDER_ID;
|
|
715
723
|
name: string;
|
|
@@ -746,6 +754,7 @@ declare type ClientOptions = {
|
|
|
746
754
|
port: string;
|
|
747
755
|
};
|
|
748
756
|
declare type KMDWalletClientConstructor = {
|
|
757
|
+
metadata: Metadata;
|
|
749
758
|
client: _algosdk.Kmd;
|
|
750
759
|
id: PROVIDER_ID;
|
|
751
760
|
algosdk: typeof _algosdk;
|
|
@@ -766,7 +775,7 @@ declare class KMDWalletClient extends BaseClient {
|
|
|
766
775
|
walletId: string;
|
|
767
776
|
id: PROVIDER_ID;
|
|
768
777
|
network: Network;
|
|
769
|
-
constructor({ client, id, wallet, password, algosdk, algodClient, network, }: KMDWalletClientConstructor);
|
|
778
|
+
constructor({ metadata, client, id, wallet, password, algosdk, algodClient, network, }: KMDWalletClientConstructor);
|
|
770
779
|
static metadata: {
|
|
771
780
|
id: PROVIDER_ID;
|
|
772
781
|
name: string;
|
|
@@ -786,4 +795,4 @@ declare class KMDWalletClient extends BaseClient {
|
|
|
786
795
|
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
787
796
|
}
|
|
788
797
|
|
|
789
|
-
export { Account, AccountInfo, AlgodClientOptions, Asset, ConfirmedTxn, DEFAULT_NETWORK, DEFAULT_NODE_BASEURL, DEFAULT_NODE_PORT, DEFAULT_NODE_TOKEN, DecodedSignedTransaction, DecodedTransaction, Network, PROVIDER_ID, Provider, TransactionsArray, Txn, TxnInfo, TxnType, Wallet, WalletClient, _default as WalletProvider, AlgoSignerClient as algosigner, DeflyWalletClient as defly, ExodusClient as exodus, initializeProviders, KMDWalletClient as kmd, MyAlgoWalletClient as myalgo, PeraWalletClient as pera, reconnectProviders, useWallet, WalletConnectClient as walletconnect };
|
|
798
|
+
export { Account, AccountInfo, AlgodClientOptions, Asset, ConfirmedTxn, DEFAULT_NETWORK, DEFAULT_NODE_BASEURL, DEFAULT_NODE_PORT, DEFAULT_NODE_TOKEN, DecodedSignedTransaction, DecodedTransaction, Metadata, Network, PROVIDER_ID, Provider, TransactionsArray, Txn, TxnInfo, TxnType, Wallet, WalletClient, _default as WalletProvider, AlgoSignerClient as algosigner, DeflyWalletClient as defly, ExodusClient as exodus, initializeProviders, KMDWalletClient as kmd, MyAlgoWalletClient as myalgo, PeraWalletClient as pera, reconnectProviders, useWallet, WalletConnectClient as walletconnect };
|