@txnlab/use-wallet 1.0.1 → 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 -34
- 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 -34
- 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,
|
|
@@ -1095,9 +1099,7 @@ class PeraWalletClient extends BaseClient {
|
|
|
1095
1099
|
}
|
|
1096
1100
|
}
|
|
1097
1101
|
async connect(onDisconnect) {
|
|
1098
|
-
this.keepWCAliveStart();
|
|
1099
1102
|
const accounts = await this.#client.connect();
|
|
1100
|
-
this.keepWCAliveStop();
|
|
1101
1103
|
this.#client.connector?.on("disconnect", onDisconnect);
|
|
1102
1104
|
if (accounts.length === 0) {
|
|
1103
1105
|
throw new Error(`No accounts found for ${PeraWalletClient.metadata.id}`);
|
|
@@ -1114,8 +1116,10 @@ class PeraWalletClient extends BaseClient {
|
|
|
1114
1116
|
}
|
|
1115
1117
|
async reconnect(onDisconnect) {
|
|
1116
1118
|
const accounts = await this.#client.reconnectSession().catch(console.info);
|
|
1119
|
+
console.log("accounts?", accounts);
|
|
1117
1120
|
this.#client.connector?.on("disconnect", onDisconnect);
|
|
1118
1121
|
if (!accounts) {
|
|
1122
|
+
onDisconnect();
|
|
1119
1123
|
return null;
|
|
1120
1124
|
}
|
|
1121
1125
|
return {
|
|
@@ -1152,12 +1156,8 @@ class PeraWalletClient extends BaseClient {
|
|
|
1152
1156
|
}
|
|
1153
1157
|
return acc;
|
|
1154
1158
|
}, []);
|
|
1155
|
-
// Play an audio file to keep Wallet Connect's web socket open on iOS
|
|
1156
|
-
// when the user goes into background mode.
|
|
1157
|
-
this.keepWCAliveStart();
|
|
1158
1159
|
// Sign them with the client.
|
|
1159
1160
|
const result = await this.#client.signTransaction([txnsToSign]);
|
|
1160
|
-
this.keepWCAliveStop();
|
|
1161
1161
|
// Join the newly signed transactions with the original group of transactions.
|
|
1162
1162
|
const signedTxns = decodedTxns.reduce((acc, txn, i) => {
|
|
1163
1163
|
if (!("txn" in txn)) {
|
|
@@ -1192,11 +1192,9 @@ class PeraWalletClient extends BaseClient {
|
|
|
1192
1192
|
/** @deprecated */
|
|
1193
1193
|
async signEncodedTransactions(transactions) {
|
|
1194
1194
|
const transactionsToSign = this.formatTransactionsArray(transactions);
|
|
1195
|
-
this.keepWCAliveStart();
|
|
1196
1195
|
const result = (await this.#client.signTransaction([
|
|
1197
1196
|
transactionsToSign,
|
|
1198
1197
|
]));
|
|
1199
|
-
this.keepWCAliveStop();
|
|
1200
1198
|
const signedTransactions = [];
|
|
1201
1199
|
let resultIndex = 0;
|
|
1202
1200
|
for (const [type, txn] of transactions) {
|
|
@@ -1222,10 +1220,11 @@ const ICON$5 = "data:image/svg+xml;base64," +
|
|
|
1222
1220
|
class MyAlgoWalletClient extends BaseClient {
|
|
1223
1221
|
#client;
|
|
1224
1222
|
network;
|
|
1225
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1226
|
-
super(algosdk, algodClient);
|
|
1223
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1224
|
+
super(metadata, algosdk, algodClient);
|
|
1227
1225
|
this.#client = client;
|
|
1228
1226
|
this.network = network;
|
|
1227
|
+
this.metadata = MyAlgoWalletClient.metadata;
|
|
1229
1228
|
}
|
|
1230
1229
|
static metadata = {
|
|
1231
1230
|
id: exports.PROVIDER_ID.MYALGO,
|
|
@@ -1242,6 +1241,7 @@ class MyAlgoWalletClient extends BaseClient {
|
|
|
1242
1241
|
...(clientOptions ? clientOptions : { disableLedgerNano: false }),
|
|
1243
1242
|
});
|
|
1244
1243
|
return new MyAlgoWalletClient({
|
|
1244
|
+
metadata: MyAlgoWalletClient.metadata,
|
|
1245
1245
|
client: myAlgo,
|
|
1246
1246
|
algosdk: algosdk,
|
|
1247
1247
|
algodClient: algodClient,
|
|
@@ -1336,10 +1336,11 @@ const ICON$4 = "data:image/svg+xml;base64," +
|
|
|
1336
1336
|
class DeflyWalletClient extends BaseClient {
|
|
1337
1337
|
#client;
|
|
1338
1338
|
network;
|
|
1339
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1340
|
-
super(algosdk, algodClient);
|
|
1339
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1340
|
+
super(metadata, algosdk, algodClient);
|
|
1341
1341
|
this.#client = client;
|
|
1342
1342
|
this.network = network;
|
|
1343
|
+
this.metadata = DeflyWalletClient.metadata;
|
|
1343
1344
|
}
|
|
1344
1345
|
static metadata = {
|
|
1345
1346
|
id: exports.PROVIDER_ID.DEFLY,
|
|
@@ -1357,6 +1358,7 @@ class DeflyWalletClient extends BaseClient {
|
|
|
1357
1358
|
...(clientOptions ? clientOptions : { shouldShowSignTxnToast: false }),
|
|
1358
1359
|
});
|
|
1359
1360
|
return new DeflyWalletClient({
|
|
1361
|
+
metadata: DeflyWalletClient.metadata,
|
|
1360
1362
|
client: deflyWallet,
|
|
1361
1363
|
algosdk,
|
|
1362
1364
|
algodClient,
|
|
@@ -1485,11 +1487,12 @@ class ExodusClient extends BaseClient {
|
|
|
1485
1487
|
#client;
|
|
1486
1488
|
#onlyIfTrusted;
|
|
1487
1489
|
network;
|
|
1488
|
-
constructor({ client, algosdk, algodClient, onlyIfTrusted, network, }) {
|
|
1489
|
-
super(algosdk, algodClient);
|
|
1490
|
+
constructor({ metadata, client, algosdk, algodClient, onlyIfTrusted, network, }) {
|
|
1491
|
+
super(metadata, algosdk, algodClient);
|
|
1490
1492
|
this.#client = client;
|
|
1491
1493
|
this.#onlyIfTrusted = onlyIfTrusted;
|
|
1492
1494
|
this.network = network;
|
|
1495
|
+
this.metadata = ExodusClient.metadata;
|
|
1493
1496
|
}
|
|
1494
1497
|
static metadata = {
|
|
1495
1498
|
id: exports.PROVIDER_ID.EXODUS,
|
|
@@ -1507,6 +1510,7 @@ class ExodusClient extends BaseClient {
|
|
|
1507
1510
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1508
1511
|
const exodus = window.exodus.algorand;
|
|
1509
1512
|
return new ExodusClient({
|
|
1513
|
+
metadata: ExodusClient.metadata,
|
|
1510
1514
|
id: exports.PROVIDER_ID.EXODUS,
|
|
1511
1515
|
client: exodus,
|
|
1512
1516
|
algosdk: algosdk,
|
|
@@ -1626,8 +1630,8 @@ const getNetwork = (network) => {
|
|
|
1626
1630
|
class AlgoSignerClient extends BaseClient {
|
|
1627
1631
|
#client;
|
|
1628
1632
|
network;
|
|
1629
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1630
|
-
super(algosdk, algodClient);
|
|
1633
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1634
|
+
super(metadata, algosdk, algodClient);
|
|
1631
1635
|
this.#client = client;
|
|
1632
1636
|
this.network = network;
|
|
1633
1637
|
}
|
|
@@ -1647,6 +1651,7 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1647
1651
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1648
1652
|
const algosigner = window.AlgoSigner;
|
|
1649
1653
|
return new AlgoSignerClient({
|
|
1654
|
+
metadata: AlgoSignerClient.metadata,
|
|
1650
1655
|
id: exports.PROVIDER_ID.ALGOSIGNER,
|
|
1651
1656
|
client: algosigner,
|
|
1652
1657
|
algosdk: algosdk,
|
|
@@ -1766,10 +1771,11 @@ const DEFAULT_NETWORK = "mainnet";
|
|
|
1766
1771
|
class WalletConnectClient extends BaseClient {
|
|
1767
1772
|
#client;
|
|
1768
1773
|
network;
|
|
1769
|
-
constructor({ client, algosdk, algodClient, network, }) {
|
|
1770
|
-
super(algosdk, algodClient);
|
|
1774
|
+
constructor({ metadata, client, algosdk, algodClient, network, }) {
|
|
1775
|
+
super(metadata, algosdk, algodClient);
|
|
1771
1776
|
this.#client = client;
|
|
1772
1777
|
this.network = network;
|
|
1778
|
+
this.metadata = WalletConnectClient.metadata;
|
|
1773
1779
|
}
|
|
1774
1780
|
static metadata = {
|
|
1775
1781
|
id: exports.PROVIDER_ID.WALLETCONNECT,
|
|
@@ -1793,6 +1799,7 @@ class WalletConnectClient extends BaseClient {
|
|
|
1793
1799
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1794
1800
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1795
1801
|
const initWallet = {
|
|
1802
|
+
metadata: WalletConnectClient.metadata,
|
|
1796
1803
|
client: walletConnect,
|
|
1797
1804
|
algosdk: algosdk,
|
|
1798
1805
|
algodClient: algodClient,
|
|
@@ -1960,14 +1967,15 @@ class KMDWalletClient extends BaseClient {
|
|
|
1960
1967
|
walletId;
|
|
1961
1968
|
id;
|
|
1962
1969
|
network;
|
|
1963
|
-
constructor({ client, id, wallet, password, algosdk, algodClient, network, }) {
|
|
1964
|
-
super(algosdk, algodClient);
|
|
1970
|
+
constructor({ metadata, client, id, wallet, password, algosdk, algodClient, network, }) {
|
|
1971
|
+
super(metadata, algosdk, algodClient);
|
|
1965
1972
|
this.#client = client;
|
|
1966
1973
|
this.#wallet = wallet;
|
|
1967
1974
|
this.#password = password;
|
|
1968
1975
|
this.id = id;
|
|
1969
1976
|
this.walletId = "";
|
|
1970
1977
|
this.network = network;
|
|
1978
|
+
this.metadata = KMDWalletClient.metadata;
|
|
1971
1979
|
}
|
|
1972
1980
|
static metadata = {
|
|
1973
1981
|
id: exports.PROVIDER_ID.KMD,
|
|
@@ -1977,11 +1985,12 @@ class KMDWalletClient extends BaseClient {
|
|
|
1977
1985
|
};
|
|
1978
1986
|
static async init({ clientOptions, algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1, }) {
|
|
1979
1987
|
try {
|
|
1980
|
-
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 || {};
|
|
1981
1989
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1982
1990
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
1983
1991
|
const kmdClient = new algosdk.Kmd(token, host, port);
|
|
1984
1992
|
return new KMDWalletClient({
|
|
1993
|
+
metadata: KMDWalletClient.metadata,
|
|
1985
1994
|
id: exports.PROVIDER_ID.KMD,
|
|
1986
1995
|
password,
|
|
1987
1996
|
wallet,
|
|
@@ -2007,10 +2016,7 @@ class KMDWalletClient extends BaseClient {
|
|
|
2007
2016
|
return;
|
|
2008
2017
|
}
|
|
2009
2018
|
async reconnect() {
|
|
2010
|
-
return
|
|
2011
|
-
...KMDWalletClient.metadata,
|
|
2012
|
-
accounts: await this.listAccounts(this.#wallet, this.#password || (await this.requestPassword())),
|
|
2013
|
-
};
|
|
2019
|
+
return null;
|
|
2014
2020
|
}
|
|
2015
2021
|
async requestPassword() {
|
|
2016
2022
|
// TODO: store it locally?
|
|
@@ -2108,6 +2114,13 @@ var allClients = {
|
|
|
2108
2114
|
[KMDWalletClient.metadata.id]: KMDWalletClient,
|
|
2109
2115
|
};
|
|
2110
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
|
+
|
|
2111
2124
|
function shallow(objA, objB) {
|
|
2112
2125
|
if (Object.is(objA, objB)) {
|
|
2113
2126
|
return true;
|
|
@@ -2129,7 +2142,7 @@ function shallow(objA, objB) {
|
|
|
2129
2142
|
|
|
2130
2143
|
function useWallet() {
|
|
2131
2144
|
const clients = require$$0.useContext(ClientContext);
|
|
2132
|
-
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount,
|
|
2145
|
+
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount, addAccounts, } = useWalletStore(walletStoreSelector, shallow);
|
|
2133
2146
|
const getAccountsByProvider = (id) => {
|
|
2134
2147
|
return connectedAccounts.filter((account) => account.providerId === id);
|
|
2135
2148
|
};
|
|
@@ -2191,7 +2204,7 @@ function useWallet() {
|
|
|
2191
2204
|
try {
|
|
2192
2205
|
await disconnectWCSessions(id);
|
|
2193
2206
|
const walletClient = await getClient(id);
|
|
2194
|
-
const walletInfo = await walletClient?.connect(() =>
|
|
2207
|
+
const walletInfo = await walletClient?.connect(() => clearAccounts(id));
|
|
2195
2208
|
if (!walletInfo || !walletInfo.accounts.length) {
|
|
2196
2209
|
throw new Error("Failed to connect " + id);
|
|
2197
2210
|
}
|
|
@@ -2205,7 +2218,7 @@ function useWallet() {
|
|
|
2205
2218
|
const reconnect = async (id) => {
|
|
2206
2219
|
try {
|
|
2207
2220
|
const walletClient = await getClient(id);
|
|
2208
|
-
const walletInfo = await walletClient?.reconnect(() =>
|
|
2221
|
+
const walletInfo = await walletClient?.reconnect(() => clearAccounts(id));
|
|
2209
2222
|
if (walletInfo && walletInfo.accounts.length) {
|
|
2210
2223
|
addAccounts(walletInfo.accounts);
|
|
2211
2224
|
}
|
|
@@ -2224,8 +2237,7 @@ function useWallet() {
|
|
|
2224
2237
|
console.error(e);
|
|
2225
2238
|
}
|
|
2226
2239
|
finally {
|
|
2227
|
-
|
|
2228
|
-
removeAccounts(id);
|
|
2240
|
+
clearAccounts(id);
|
|
2229
2241
|
}
|
|
2230
2242
|
};
|
|
2231
2243
|
const setActive = async (id) => {
|
|
@@ -2335,7 +2347,7 @@ const reconnectProviders = async (providers) => {
|
|
|
2335
2347
|
const clients = Object.values(providers);
|
|
2336
2348
|
for (const client of clients) {
|
|
2337
2349
|
const c = await client;
|
|
2338
|
-
c?.reconnect(c?.
|
|
2350
|
+
c?.reconnect(() => clearAccounts(c?.metadata.id));
|
|
2339
2351
|
}
|
|
2340
2352
|
}
|
|
2341
2353
|
catch (e) {
|