@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
|
@@ -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/cjs/index.js
CHANGED
|
@@ -941,11 +941,13 @@ class BaseClient {
|
|
|
941
941
|
algosdk;
|
|
942
942
|
algodClient;
|
|
943
943
|
keepWCAlive;
|
|
944
|
+
metadata;
|
|
944
945
|
static metadata;
|
|
945
|
-
constructor(algosdk, algodClient) {
|
|
946
|
+
constructor(metadata, algosdk, algodClient) {
|
|
946
947
|
this.algosdk = algosdk;
|
|
947
948
|
this.algodClient = algodClient;
|
|
948
949
|
this.keepWCAlive = new Audio();
|
|
950
|
+
this.metadata = metadata;
|
|
949
951
|
}
|
|
950
952
|
async healthCheck() {
|
|
951
953
|
return await this.algodClient.healthCheck().do();
|
|
@@ -1063,10 +1065,11 @@ const ICON$6 = "data:image/svg+xml;base64," +
|
|
|
1063
1065
|
class PeraWalletClient extends BaseClient {
|
|
1064
1066
|
#client;
|
|
1065
1067
|
network;
|
|
1066
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1067
|
-
super(algosdk, algodClient);
|
|
1068
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1069
|
+
super(metadata, algosdk, algodClient);
|
|
1068
1070
|
this.#client = client;
|
|
1069
1071
|
this.network = network;
|
|
1072
|
+
this.metadata = PeraWalletClient.metadata;
|
|
1070
1073
|
}
|
|
1071
1074
|
static metadata = {
|
|
1072
1075
|
id: exports.PROVIDER_ID.PERA,
|
|
@@ -1083,6 +1086,7 @@ class PeraWalletClient extends BaseClient {
|
|
|
1083
1086
|
...(clientOptions ? clientOptions : { shouldShowSignTxnToast: false }),
|
|
1084
1087
|
});
|
|
1085
1088
|
return new PeraWalletClient({
|
|
1089
|
+
metadata: PeraWalletClient.metadata,
|
|
1086
1090
|
client: peraWallet,
|
|
1087
1091
|
algosdk,
|
|
1088
1092
|
algodClient,
|
|
@@ -1112,8 +1116,10 @@ class PeraWalletClient extends BaseClient {
|
|
|
1112
1116
|
}
|
|
1113
1117
|
async reconnect(onDisconnect) {
|
|
1114
1118
|
const accounts = await this.#client.reconnectSession().catch(console.info);
|
|
1119
|
+
console.log("accounts?", accounts);
|
|
1115
1120
|
this.#client.connector?.on("disconnect", onDisconnect);
|
|
1116
1121
|
if (!accounts) {
|
|
1122
|
+
onDisconnect();
|
|
1117
1123
|
return null;
|
|
1118
1124
|
}
|
|
1119
1125
|
return {
|
|
@@ -1214,10 +1220,11 @@ const ICON$5 = "data:image/svg+xml;base64," +
|
|
|
1214
1220
|
class MyAlgoWalletClient extends BaseClient {
|
|
1215
1221
|
#client;
|
|
1216
1222
|
network;
|
|
1217
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1218
|
-
super(algosdk, algodClient);
|
|
1223
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1224
|
+
super(metadata, algosdk, algodClient);
|
|
1219
1225
|
this.#client = client;
|
|
1220
1226
|
this.network = network;
|
|
1227
|
+
this.metadata = MyAlgoWalletClient.metadata;
|
|
1221
1228
|
}
|
|
1222
1229
|
static metadata = {
|
|
1223
1230
|
id: exports.PROVIDER_ID.MYALGO,
|
|
@@ -1234,6 +1241,7 @@ class MyAlgoWalletClient extends BaseClient {
|
|
|
1234
1241
|
...(clientOptions ? clientOptions : { disableLedgerNano: false }),
|
|
1235
1242
|
});
|
|
1236
1243
|
return new MyAlgoWalletClient({
|
|
1244
|
+
metadata: MyAlgoWalletClient.metadata,
|
|
1237
1245
|
client: myAlgo,
|
|
1238
1246
|
algosdk: algosdk,
|
|
1239
1247
|
algodClient: algodClient,
|
|
@@ -1328,10 +1336,11 @@ const ICON$4 = "data:image/svg+xml;base64," +
|
|
|
1328
1336
|
class DeflyWalletClient extends BaseClient {
|
|
1329
1337
|
#client;
|
|
1330
1338
|
network;
|
|
1331
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1332
|
-
super(algosdk, algodClient);
|
|
1339
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1340
|
+
super(metadata, algosdk, algodClient);
|
|
1333
1341
|
this.#client = client;
|
|
1334
1342
|
this.network = network;
|
|
1343
|
+
this.metadata = DeflyWalletClient.metadata;
|
|
1335
1344
|
}
|
|
1336
1345
|
static metadata = {
|
|
1337
1346
|
id: exports.PROVIDER_ID.DEFLY,
|
|
@@ -1349,6 +1358,7 @@ class DeflyWalletClient extends BaseClient {
|
|
|
1349
1358
|
...(clientOptions ? clientOptions : { shouldShowSignTxnToast: false }),
|
|
1350
1359
|
});
|
|
1351
1360
|
return new DeflyWalletClient({
|
|
1361
|
+
metadata: DeflyWalletClient.metadata,
|
|
1352
1362
|
client: deflyWallet,
|
|
1353
1363
|
algosdk,
|
|
1354
1364
|
algodClient,
|
|
@@ -1477,11 +1487,12 @@ class ExodusClient extends BaseClient {
|
|
|
1477
1487
|
#client;
|
|
1478
1488
|
#onlyIfTrusted;
|
|
1479
1489
|
network;
|
|
1480
|
-
constructor({ client, algosdk, algodClient, onlyIfTrusted, network, }) {
|
|
1481
|
-
super(algosdk, algodClient);
|
|
1490
|
+
constructor({ metadata, client, algosdk, algodClient, onlyIfTrusted, network, }) {
|
|
1491
|
+
super(metadata, algosdk, algodClient);
|
|
1482
1492
|
this.#client = client;
|
|
1483
1493
|
this.#onlyIfTrusted = onlyIfTrusted;
|
|
1484
1494
|
this.network = network;
|
|
1495
|
+
this.metadata = ExodusClient.metadata;
|
|
1485
1496
|
}
|
|
1486
1497
|
static metadata = {
|
|
1487
1498
|
id: exports.PROVIDER_ID.EXODUS,
|
|
@@ -1499,6 +1510,7 @@ class ExodusClient extends BaseClient {
|
|
|
1499
1510
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1500
1511
|
const exodus = window.exodus.algorand;
|
|
1501
1512
|
return new ExodusClient({
|
|
1513
|
+
metadata: ExodusClient.metadata,
|
|
1502
1514
|
id: exports.PROVIDER_ID.EXODUS,
|
|
1503
1515
|
client: exodus,
|
|
1504
1516
|
algosdk: algosdk,
|
|
@@ -1618,8 +1630,8 @@ const getNetwork = (network) => {
|
|
|
1618
1630
|
class AlgoSignerClient extends BaseClient {
|
|
1619
1631
|
#client;
|
|
1620
1632
|
network;
|
|
1621
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1622
|
-
super(algosdk, algodClient);
|
|
1633
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1634
|
+
super(metadata, algosdk, algodClient);
|
|
1623
1635
|
this.#client = client;
|
|
1624
1636
|
this.network = network;
|
|
1625
1637
|
}
|
|
@@ -1639,6 +1651,7 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1639
1651
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1640
1652
|
const algosigner = window.AlgoSigner;
|
|
1641
1653
|
return new AlgoSignerClient({
|
|
1654
|
+
metadata: AlgoSignerClient.metadata,
|
|
1642
1655
|
id: exports.PROVIDER_ID.ALGOSIGNER,
|
|
1643
1656
|
client: algosigner,
|
|
1644
1657
|
algosdk: algosdk,
|
|
@@ -1758,10 +1771,11 @@ const DEFAULT_NETWORK = "mainnet";
|
|
|
1758
1771
|
class WalletConnectClient extends BaseClient {
|
|
1759
1772
|
#client;
|
|
1760
1773
|
network;
|
|
1761
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1762
|
-
super(algosdk, algodClient);
|
|
1774
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1775
|
+
super(metadata, algosdk, algodClient);
|
|
1763
1776
|
this.#client = client;
|
|
1764
1777
|
this.network = network;
|
|
1778
|
+
this.metadata = WalletConnectClient.metadata;
|
|
1765
1779
|
}
|
|
1766
1780
|
static metadata = {
|
|
1767
1781
|
id: exports.PROVIDER_ID.WALLETCONNECT,
|
|
@@ -1785,6 +1799,7 @@ class WalletConnectClient extends BaseClient {
|
|
|
1785
1799
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1786
1800
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1787
1801
|
const initWallet = {
|
|
1802
|
+
metadata: WalletConnectClient.metadata,
|
|
1788
1803
|
client: walletConnect,
|
|
1789
1804
|
algosdk: algosdk,
|
|
1790
1805
|
algodClient: algodClient,
|
|
@@ -1952,14 +1967,15 @@ class KMDWalletClient extends BaseClient {
|
|
|
1952
1967
|
walletId;
|
|
1953
1968
|
id;
|
|
1954
1969
|
network;
|
|
1955
|
-
constructor({ client, id, wallet, password, algosdk, algodClient, network, }) {
|
|
1956
|
-
super(algosdk, algodClient);
|
|
1970
|
+
constructor({ metadata, client, id, wallet, password, algosdk, algodClient, network, }) {
|
|
1971
|
+
super(metadata, algosdk, algodClient);
|
|
1957
1972
|
this.#client = client;
|
|
1958
1973
|
this.#wallet = wallet;
|
|
1959
1974
|
this.#password = password;
|
|
1960
1975
|
this.id = id;
|
|
1961
1976
|
this.walletId = "";
|
|
1962
1977
|
this.network = network;
|
|
1978
|
+
this.metadata = KMDWalletClient.metadata;
|
|
1963
1979
|
}
|
|
1964
1980
|
static metadata = {
|
|
1965
1981
|
id: exports.PROVIDER_ID.KMD,
|
|
@@ -1969,11 +1985,12 @@ class KMDWalletClient extends BaseClient {
|
|
|
1969
1985
|
};
|
|
1970
1986
|
static async init({ clientOptions, algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1, }) {
|
|
1971
1987
|
try {
|
|
1972
|
-
const { token = "a".repeat(64), host = "http://localhost", port = "4002", wallet = "", password = "", } = clientOptions || {};
|
|
1988
|
+
const { token = "a".repeat(64), host = "http://localhost", port = "4002", wallet = "unencrypted-default-wallet", password = "", } = clientOptions || {};
|
|
1973
1989
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1974
1990
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1975
1991
|
const kmdClient = new algosdk.Kmd(token, host, port);
|
|
1976
1992
|
return new KMDWalletClient({
|
|
1993
|
+
metadata: KMDWalletClient.metadata,
|
|
1977
1994
|
id: exports.PROVIDER_ID.KMD,
|
|
1978
1995
|
password,
|
|
1979
1996
|
wallet,
|
|
@@ -1999,10 +2016,7 @@ class KMDWalletClient extends BaseClient {
|
|
|
1999
2016
|
return;
|
|
2000
2017
|
}
|
|
2001
2018
|
async reconnect() {
|
|
2002
|
-
return
|
|
2003
|
-
...KMDWalletClient.metadata,
|
|
2004
|
-
accounts: await this.listAccounts(this.#wallet, this.#password || (await this.requestPassword())),
|
|
2005
|
-
};
|
|
2019
|
+
return null;
|
|
2006
2020
|
}
|
|
2007
2021
|
async requestPassword() {
|
|
2008
2022
|
// TODO: store it locally?
|
|
@@ -2100,6 +2114,13 @@ var allClients = {
|
|
|
2100
2114
|
[KMDWalletClient.metadata.id]: KMDWalletClient,
|
|
2101
2115
|
};
|
|
2102
2116
|
|
|
2117
|
+
const clearActiveAccount = useWalletStore.getState().clearActiveAccount;
|
|
2118
|
+
const removeAccounts = useWalletStore.getState().removeAccounts;
|
|
2119
|
+
const clearAccounts = (id) => {
|
|
2120
|
+
clearActiveAccount(id);
|
|
2121
|
+
removeAccounts(id);
|
|
2122
|
+
};
|
|
2123
|
+
|
|
2103
2124
|
function shallow(objA, objB) {
|
|
2104
2125
|
if (Object.is(objA, objB)) {
|
|
2105
2126
|
return true;
|
|
@@ -2121,7 +2142,7 @@ function shallow(objA, objB) {
|
|
|
2121
2142
|
|
|
2122
2143
|
function useWallet() {
|
|
2123
2144
|
const clients = require$$0.useContext(ClientContext);
|
|
2124
|
-
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount,
|
|
2145
|
+
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount, addAccounts, } = useWalletStore(walletStoreSelector, shallow);
|
|
2125
2146
|
const getAccountsByProvider = (id) => {
|
|
2126
2147
|
return connectedAccounts.filter((account) => account.providerId === id);
|
|
2127
2148
|
};
|
|
@@ -2183,7 +2204,7 @@ function useWallet() {
|
|
|
2183
2204
|
try {
|
|
2184
2205
|
await disconnectWCSessions(id);
|
|
2185
2206
|
const walletClient = await getClient(id);
|
|
2186
|
-
const walletInfo = await walletClient?.connect(() =>
|
|
2207
|
+
const walletInfo = await walletClient?.connect(() => clearAccounts(id));
|
|
2187
2208
|
if (!walletInfo || !walletInfo.accounts.length) {
|
|
2188
2209
|
throw new Error("Failed to connect " + id);
|
|
2189
2210
|
}
|
|
@@ -2197,7 +2218,7 @@ function useWallet() {
|
|
|
2197
2218
|
const reconnect = async (id) => {
|
|
2198
2219
|
try {
|
|
2199
2220
|
const walletClient = await getClient(id);
|
|
2200
|
-
const walletInfo = await walletClient?.reconnect(() =>
|
|
2221
|
+
const walletInfo = await walletClient?.reconnect(() => clearAccounts(id));
|
|
2201
2222
|
if (walletInfo && walletInfo.accounts.length) {
|
|
2202
2223
|
addAccounts(walletInfo.accounts);
|
|
2203
2224
|
}
|
|
@@ -2216,8 +2237,7 @@ function useWallet() {
|
|
|
2216
2237
|
console.error(e);
|
|
2217
2238
|
}
|
|
2218
2239
|
finally {
|
|
2219
|
-
|
|
2220
|
-
removeAccounts(id);
|
|
2240
|
+
clearAccounts(id);
|
|
2221
2241
|
}
|
|
2222
2242
|
};
|
|
2223
2243
|
const setActive = async (id) => {
|
|
@@ -2327,7 +2347,7 @@ const reconnectProviders = async (providers) => {
|
|
|
2327
2347
|
const clients = Object.values(providers);
|
|
2328
2348
|
for (const client of clients) {
|
|
2329
2349
|
const c = await client;
|
|
2330
|
-
c?.reconnect(c?.
|
|
2350
|
+
c?.reconnect(() => clearAccounts(c?.metadata.id));
|
|
2331
2351
|
}
|
|
2332
2352
|
}
|
|
2333
2353
|
catch (e) {
|