@txnlab/use-wallet-react 3.0.0-alpha.2 → 3.0.0-beta.1
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/LICENSE.md +20 -0
- package/README.md +2 -2
- package/dist/index.cjs +27 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +26 -23
- package/dist/index.js.map +1 -1
- package/package.json +28 -24
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2022 TxnLab Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @txnlab/use-wallet-react
|
|
2
2
|
|
|
3
|
-
React
|
|
3
|
+
React adapter for [@txnlab/use-wallet](https://github.com/TxnLab/use-wallet/tree/v3/packages/use-wallet)
|
|
4
4
|
|
|
5
5
|
## License
|
|
6
6
|
|
|
7
|
-
MIT ©
|
|
7
|
+
MIT ©2024 [TxnLab, Inc.](https://txnlab.dev)
|
package/dist/index.cjs
CHANGED
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -34,6 +35,7 @@ __export(src_exports, {
|
|
|
34
35
|
useWallet: () => useWallet
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
__reExport(src_exports, require("@txnlab/use-wallet"), module.exports);
|
|
37
39
|
|
|
38
40
|
// src/useWallet.ts
|
|
39
41
|
var import_react_store = require("@tanstack/react-store");
|
|
@@ -50,6 +52,7 @@ var useWalletManager = () => {
|
|
|
50
52
|
return manager;
|
|
51
53
|
};
|
|
52
54
|
var WalletProvider = ({ manager, children }) => {
|
|
55
|
+
const resumedRef = React.useRef(false);
|
|
53
56
|
React.useEffect(() => {
|
|
54
57
|
const resumeSessions = async () => {
|
|
55
58
|
try {
|
|
@@ -58,8 +61,11 @@ var WalletProvider = ({ manager, children }) => {
|
|
|
58
61
|
console.error("Error resuming sessions:", error);
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
if (!resumedRef.current) {
|
|
65
|
+
resumeSessions();
|
|
66
|
+
resumedRef.current = true;
|
|
67
|
+
}
|
|
68
|
+
}, [manager, resumedRef.current]);
|
|
63
69
|
return /* @__PURE__ */ React.createElement(WalletContext.Provider, { value: manager }, children);
|
|
64
70
|
};
|
|
65
71
|
|
|
@@ -69,27 +75,23 @@ function useWallet() {
|
|
|
69
75
|
const algodClient = manager.algodClient;
|
|
70
76
|
const walletStateMap = (0, import_react_store.useStore)(manager.store, (state) => state.wallets);
|
|
71
77
|
const activeWalletId = (0, import_react_store.useStore)(manager.store, (state) => state.activeWallet);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
}, [walletsArray, walletStateMap, activeWalletId]);
|
|
78
|
+
const wallets = React2.useMemo(() => {
|
|
79
|
+
return [...manager.wallets.values()].map((wallet) => {
|
|
80
|
+
const walletState = walletStateMap[wallet.id];
|
|
81
|
+
return {
|
|
82
|
+
id: wallet.id,
|
|
83
|
+
metadata: wallet.metadata,
|
|
84
|
+
accounts: walletState?.accounts ?? [],
|
|
85
|
+
activeAccount: walletState?.activeAccount ?? null,
|
|
86
|
+
isConnected: !!walletState,
|
|
87
|
+
isActive: wallet.id === activeWalletId,
|
|
88
|
+
connect: () => wallet.connect(),
|
|
89
|
+
disconnect: () => wallet.disconnect(),
|
|
90
|
+
setActive: () => wallet.setActive(),
|
|
91
|
+
setActiveAccount: (addr) => wallet.setActiveAccount(addr)
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}, [manager, walletStateMap, activeWalletId]);
|
|
93
95
|
const activeWallet = activeWalletId ? manager.getWallet(activeWalletId) || null : null;
|
|
94
96
|
const activeWalletState = activeWalletId ? walletStateMap[activeWalletId] || null : null;
|
|
95
97
|
const activeWalletAccounts = activeWalletState?.accounts ?? null;
|
|
@@ -127,6 +129,7 @@ function useWallet() {
|
|
|
127
129
|
// Annotate the CommonJS export names for ESM import in node:
|
|
128
130
|
0 && (module.exports = {
|
|
129
131
|
WalletProvider,
|
|
130
|
-
useWallet
|
|
132
|
+
useWallet,
|
|
133
|
+
...require("@txnlab/use-wallet")
|
|
131
134
|
});
|
|
132
135
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/useWallet.ts","../src/WalletProvider.tsx"],"sourcesContent":["export { useWallet } from './useWallet'\nexport { WalletProvider } from './WalletProvider'\n","'use client'\n\nimport { useStore } from '@tanstack/react-store'\nimport * as React from 'react'\nimport { useWalletManager } from './WalletProvider'\nimport type { WalletAccount, WalletMetadata } from '@txnlab/use-wallet
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/useWallet.ts","../src/WalletProvider.tsx"],"sourcesContent":["export * from '@txnlab/use-wallet'\nexport { useWallet, Wallet } from './useWallet'\nexport { WalletProvider } from './WalletProvider'\n","'use client'\n\nimport { useStore } from '@tanstack/react-store'\nimport * as React from 'react'\nimport { useWalletManager } from './WalletProvider'\nimport type { WalletAccount, WalletMetadata } from '@txnlab/use-wallet'\nimport type algosdk from 'algosdk'\n\nexport interface Wallet {\n id: string\n metadata: WalletMetadata\n accounts: WalletAccount[]\n activeAccount: WalletAccount | null\n isConnected: boolean\n isActive: boolean\n connect: () => Promise<WalletAccount[]>\n disconnect: () => Promise<void>\n setActive: () => void\n setActiveAccount: (address: string) => void\n}\n\nexport function useWallet() {\n const manager = useWalletManager()\n\n const algodClient: algosdk.Algodv2 = manager.algodClient\n\n const walletStateMap = useStore(manager.store, (state) => state.wallets)\n const activeWalletId = useStore(manager.store, (state) => state.activeWallet)\n\n const wallets = React.useMemo(() => {\n return [...manager.wallets.values()].map((wallet): Wallet => {\n const walletState = walletStateMap[wallet.id]\n\n return {\n id: wallet.id,\n metadata: wallet.metadata,\n accounts: walletState?.accounts ?? [],\n activeAccount: walletState?.activeAccount ?? null,\n isConnected: !!walletState,\n isActive: wallet.id === activeWalletId,\n connect: () => wallet.connect(),\n disconnect: () => wallet.disconnect(),\n setActive: () => wallet.setActive(),\n setActiveAccount: (addr) => wallet.setActiveAccount(addr)\n }\n })\n }, [manager, walletStateMap, activeWalletId])\n\n const activeWallet = activeWalletId ? manager.getWallet(activeWalletId) || null : null\n const activeWalletState = activeWalletId ? walletStateMap[activeWalletId] || null : null\n\n const activeWalletAccounts = activeWalletState?.accounts ?? null\n const activeWalletAddresses = activeWalletAccounts?.map((account) => account.address) ?? null\n const activeAccount = activeWalletState?.activeAccount ?? null\n const activeAddress = activeAccount?.address ?? null\n\n const activeNetwork = useStore(manager.store, (state) => state.activeNetwork)\n const setActiveNetwork = manager.setActiveNetwork\n\n const signTransactions = (\n txnGroup: algosdk.Transaction[] | algosdk.Transaction[][] | Uint8Array[] | Uint8Array[][],\n indexesToSign?: number[],\n returnGroup?: boolean\n ) => {\n if (!activeWallet) {\n throw new Error('No active wallet')\n }\n return activeWallet.signTransactions(txnGroup, indexesToSign, returnGroup)\n }\n\n const transactionSigner = (txnGroup: algosdk.Transaction[], indexesToSign: number[]) => {\n if (!activeWallet) {\n throw new Error('No active wallet')\n }\n return activeWallet.transactionSigner(txnGroup, indexesToSign)\n }\n\n return {\n wallets,\n algodClient,\n activeNetwork,\n activeWallet,\n activeWalletAccounts,\n activeWalletAddresses,\n activeAccount,\n activeAddress,\n setActiveNetwork,\n signTransactions,\n transactionSigner\n }\n}\n","'use client'\n\nimport { WalletManager } from '@txnlab/use-wallet'\nimport * as React from 'react'\n\nconst WalletContext = React.createContext<WalletManager | undefined>(undefined)\n\nexport const useWalletManager = () => {\n const manager = React.useContext(WalletContext)\n\n if (!manager) {\n throw new Error('useWallet must be used within the WalletProvider')\n }\n\n return manager\n}\n\ninterface WalletProviderProps {\n manager: WalletManager\n children: React.ReactNode\n}\n\nexport const WalletProvider = ({ manager, children }: WalletProviderProps): JSX.Element => {\n const resumedRef = React.useRef(false)\n\n React.useEffect(() => {\n const resumeSessions = async () => {\n try {\n await manager.resumeSessions()\n } catch (error) {\n console.error('Error resuming sessions:', error)\n }\n }\n\n if (!resumedRef.current) {\n resumeSessions()\n resumedRef.current = true\n }\n }, [manager, resumedRef.current])\n\n return <WalletContext.Provider value={manager}>{children}</WalletContext.Provider>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,+BAAd;;;ACEA,yBAAyB;AACzB,IAAAA,SAAuB;;;ACAvB,YAAuB;AAEvB,IAAM,gBAAsB,oBAAyC,MAAS;AAEvE,IAAM,mBAAmB,MAAM;AACpC,QAAM,UAAgB,iBAAW,aAAa;AAE9C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAEA,SAAO;AACT;AAOO,IAAM,iBAAiB,CAAC,EAAE,SAAS,SAAS,MAAwC;AACzF,QAAM,aAAmB,aAAO,KAAK;AAErC,EAAM,gBAAU,MAAM;AACpB,UAAM,iBAAiB,YAAY;AACjC,UAAI;AACF,cAAM,QAAQ,eAAe;AAAA,MAC/B,SAAS,OAAO;AACd,gBAAQ,MAAM,4BAA4B,KAAK;AAAA,MACjD;AAAA,IACF;AAEA,QAAI,CAAC,WAAW,SAAS;AACvB,qBAAe;AACf,iBAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,SAAS,WAAW,OAAO,CAAC;AAEhC,SAAO,oCAAC,cAAc,UAAd,EAAuB,OAAO,WAAU,QAAS;AAC3D;;;ADpBO,SAAS,YAAY;AAC1B,QAAM,UAAU,iBAAiB;AAEjC,QAAM,cAA+B,QAAQ;AAE7C,QAAM,qBAAiB,6BAAS,QAAQ,OAAO,CAAC,UAA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UAAiC,kBAA4B;AACtF,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,WAAO,aAAa,kBAAkB,UAAU,aAAa;AAAA,EAC/D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["React"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
1
|
+
import * as _txnlab_use_wallet from '@txnlab/use-wallet';
|
|
2
|
+
import { WalletMetadata, WalletAccount, WalletManager } from '@txnlab/use-wallet';
|
|
3
|
+
export * from '@txnlab/use-wallet';
|
|
3
4
|
import algosdk from 'algosdk';
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
|
|
@@ -18,13 +19,13 @@ interface Wallet {
|
|
|
18
19
|
declare function useWallet(): {
|
|
19
20
|
wallets: Wallet[];
|
|
20
21
|
algodClient: algosdk.Algodv2;
|
|
21
|
-
activeNetwork:
|
|
22
|
-
activeWallet:
|
|
22
|
+
activeNetwork: _txnlab_use_wallet.NetworkId;
|
|
23
|
+
activeWallet: _txnlab_use_wallet.BaseWallet | null;
|
|
23
24
|
activeWalletAccounts: WalletAccount[] | null;
|
|
24
25
|
activeWalletAddresses: string[] | null;
|
|
25
26
|
activeAccount: WalletAccount | null;
|
|
26
27
|
activeAddress: string | null;
|
|
27
|
-
setActiveNetwork: (networkId:
|
|
28
|
+
setActiveNetwork: (networkId: _txnlab_use_wallet.NetworkId) => void;
|
|
28
29
|
signTransactions: (txnGroup: algosdk.Transaction[] | algosdk.Transaction[][] | Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean) => Promise<Uint8Array[]>;
|
|
29
30
|
transactionSigner: (txnGroup: algosdk.Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>;
|
|
30
31
|
};
|
|
@@ -35,4 +36,4 @@ interface WalletProviderProps {
|
|
|
35
36
|
}
|
|
36
37
|
declare const WalletProvider: ({ manager, children }: WalletProviderProps) => JSX.Element;
|
|
37
38
|
|
|
38
|
-
export { WalletProvider, useWallet };
|
|
39
|
+
export { type Wallet, WalletProvider, useWallet };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
1
|
+
import * as _txnlab_use_wallet from '@txnlab/use-wallet';
|
|
2
|
+
import { WalletMetadata, WalletAccount, WalletManager } from '@txnlab/use-wallet';
|
|
3
|
+
export * from '@txnlab/use-wallet';
|
|
3
4
|
import algosdk from 'algosdk';
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
|
|
@@ -18,13 +19,13 @@ interface Wallet {
|
|
|
18
19
|
declare function useWallet(): {
|
|
19
20
|
wallets: Wallet[];
|
|
20
21
|
algodClient: algosdk.Algodv2;
|
|
21
|
-
activeNetwork:
|
|
22
|
-
activeWallet:
|
|
22
|
+
activeNetwork: _txnlab_use_wallet.NetworkId;
|
|
23
|
+
activeWallet: _txnlab_use_wallet.BaseWallet | null;
|
|
23
24
|
activeWalletAccounts: WalletAccount[] | null;
|
|
24
25
|
activeWalletAddresses: string[] | null;
|
|
25
26
|
activeAccount: WalletAccount | null;
|
|
26
27
|
activeAddress: string | null;
|
|
27
|
-
setActiveNetwork: (networkId:
|
|
28
|
+
setActiveNetwork: (networkId: _txnlab_use_wallet.NetworkId) => void;
|
|
28
29
|
signTransactions: (txnGroup: algosdk.Transaction[] | algosdk.Transaction[][] | Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean) => Promise<Uint8Array[]>;
|
|
29
30
|
transactionSigner: (txnGroup: algosdk.Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>;
|
|
30
31
|
};
|
|
@@ -35,4 +36,4 @@ interface WalletProviderProps {
|
|
|
35
36
|
}
|
|
36
37
|
declare const WalletProvider: ({ manager, children }: WalletProviderProps) => JSX.Element;
|
|
37
38
|
|
|
38
|
-
export { WalletProvider, useWallet };
|
|
39
|
+
export { type Wallet, WalletProvider, useWallet };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "@txnlab/use-wallet";
|
|
3
|
+
|
|
1
4
|
// src/useWallet.ts
|
|
2
5
|
import { useStore } from "@tanstack/react-store";
|
|
3
6
|
import * as React2 from "react";
|
|
@@ -13,6 +16,7 @@ var useWalletManager = () => {
|
|
|
13
16
|
return manager;
|
|
14
17
|
};
|
|
15
18
|
var WalletProvider = ({ manager, children }) => {
|
|
19
|
+
const resumedRef = React.useRef(false);
|
|
16
20
|
React.useEffect(() => {
|
|
17
21
|
const resumeSessions = async () => {
|
|
18
22
|
try {
|
|
@@ -21,8 +25,11 @@ var WalletProvider = ({ manager, children }) => {
|
|
|
21
25
|
console.error("Error resuming sessions:", error);
|
|
22
26
|
}
|
|
23
27
|
};
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
if (!resumedRef.current) {
|
|
29
|
+
resumeSessions();
|
|
30
|
+
resumedRef.current = true;
|
|
31
|
+
}
|
|
32
|
+
}, [manager, resumedRef.current]);
|
|
26
33
|
return /* @__PURE__ */ React.createElement(WalletContext.Provider, { value: manager }, children);
|
|
27
34
|
};
|
|
28
35
|
|
|
@@ -32,27 +39,23 @@ function useWallet() {
|
|
|
32
39
|
const algodClient = manager.algodClient;
|
|
33
40
|
const walletStateMap = useStore(manager.store, (state) => state.wallets);
|
|
34
41
|
const activeWalletId = useStore(manager.store, (state) => state.activeWallet);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
}, [walletsArray, walletStateMap, activeWalletId]);
|
|
42
|
+
const wallets = React2.useMemo(() => {
|
|
43
|
+
return [...manager.wallets.values()].map((wallet) => {
|
|
44
|
+
const walletState = walletStateMap[wallet.id];
|
|
45
|
+
return {
|
|
46
|
+
id: wallet.id,
|
|
47
|
+
metadata: wallet.metadata,
|
|
48
|
+
accounts: walletState?.accounts ?? [],
|
|
49
|
+
activeAccount: walletState?.activeAccount ?? null,
|
|
50
|
+
isConnected: !!walletState,
|
|
51
|
+
isActive: wallet.id === activeWalletId,
|
|
52
|
+
connect: () => wallet.connect(),
|
|
53
|
+
disconnect: () => wallet.disconnect(),
|
|
54
|
+
setActive: () => wallet.setActive(),
|
|
55
|
+
setActiveAccount: (addr) => wallet.setActiveAccount(addr)
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}, [manager, walletStateMap, activeWalletId]);
|
|
56
59
|
const activeWallet = activeWalletId ? manager.getWallet(activeWalletId) || null : null;
|
|
57
60
|
const activeWalletState = activeWalletId ? walletStateMap[activeWalletId] || null : null;
|
|
58
61
|
const activeWalletAccounts = activeWalletState?.accounts ?? null;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useWallet.ts","../src/WalletProvider.tsx"],"sourcesContent":["'use client'\n\nimport { useStore } from '@tanstack/react-store'\nimport * as React from 'react'\nimport { useWalletManager } from './WalletProvider'\nimport type { WalletAccount, WalletMetadata } from '@txnlab/use-wallet
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/useWallet.ts","../src/WalletProvider.tsx"],"sourcesContent":["export * from '@txnlab/use-wallet'\nexport { useWallet, Wallet } from './useWallet'\nexport { WalletProvider } from './WalletProvider'\n","'use client'\n\nimport { useStore } from '@tanstack/react-store'\nimport * as React from 'react'\nimport { useWalletManager } from './WalletProvider'\nimport type { WalletAccount, WalletMetadata } from '@txnlab/use-wallet'\nimport type algosdk from 'algosdk'\n\nexport interface Wallet {\n id: string\n metadata: WalletMetadata\n accounts: WalletAccount[]\n activeAccount: WalletAccount | null\n isConnected: boolean\n isActive: boolean\n connect: () => Promise<WalletAccount[]>\n disconnect: () => Promise<void>\n setActive: () => void\n setActiveAccount: (address: string) => void\n}\n\nexport function useWallet() {\n const manager = useWalletManager()\n\n const algodClient: algosdk.Algodv2 = manager.algodClient\n\n const walletStateMap = useStore(manager.store, (state) => state.wallets)\n const activeWalletId = useStore(manager.store, (state) => state.activeWallet)\n\n const wallets = React.useMemo(() => {\n return [...manager.wallets.values()].map((wallet): Wallet => {\n const walletState = walletStateMap[wallet.id]\n\n return {\n id: wallet.id,\n metadata: wallet.metadata,\n accounts: walletState?.accounts ?? [],\n activeAccount: walletState?.activeAccount ?? null,\n isConnected: !!walletState,\n isActive: wallet.id === activeWalletId,\n connect: () => wallet.connect(),\n disconnect: () => wallet.disconnect(),\n setActive: () => wallet.setActive(),\n setActiveAccount: (addr) => wallet.setActiveAccount(addr)\n }\n })\n }, [manager, walletStateMap, activeWalletId])\n\n const activeWallet = activeWalletId ? manager.getWallet(activeWalletId) || null : null\n const activeWalletState = activeWalletId ? walletStateMap[activeWalletId] || null : null\n\n const activeWalletAccounts = activeWalletState?.accounts ?? null\n const activeWalletAddresses = activeWalletAccounts?.map((account) => account.address) ?? null\n const activeAccount = activeWalletState?.activeAccount ?? null\n const activeAddress = activeAccount?.address ?? null\n\n const activeNetwork = useStore(manager.store, (state) => state.activeNetwork)\n const setActiveNetwork = manager.setActiveNetwork\n\n const signTransactions = (\n txnGroup: algosdk.Transaction[] | algosdk.Transaction[][] | Uint8Array[] | Uint8Array[][],\n indexesToSign?: number[],\n returnGroup?: boolean\n ) => {\n if (!activeWallet) {\n throw new Error('No active wallet')\n }\n return activeWallet.signTransactions(txnGroup, indexesToSign, returnGroup)\n }\n\n const transactionSigner = (txnGroup: algosdk.Transaction[], indexesToSign: number[]) => {\n if (!activeWallet) {\n throw new Error('No active wallet')\n }\n return activeWallet.transactionSigner(txnGroup, indexesToSign)\n }\n\n return {\n wallets,\n algodClient,\n activeNetwork,\n activeWallet,\n activeWalletAccounts,\n activeWalletAddresses,\n activeAccount,\n activeAddress,\n setActiveNetwork,\n signTransactions,\n transactionSigner\n }\n}\n","'use client'\n\nimport { WalletManager } from '@txnlab/use-wallet'\nimport * as React from 'react'\n\nconst WalletContext = React.createContext<WalletManager | undefined>(undefined)\n\nexport const useWalletManager = () => {\n const manager = React.useContext(WalletContext)\n\n if (!manager) {\n throw new Error('useWallet must be used within the WalletProvider')\n }\n\n return manager\n}\n\ninterface WalletProviderProps {\n manager: WalletManager\n children: React.ReactNode\n}\n\nexport const WalletProvider = ({ manager, children }: WalletProviderProps): JSX.Element => {\n const resumedRef = React.useRef(false)\n\n React.useEffect(() => {\n const resumeSessions = async () => {\n try {\n await manager.resumeSessions()\n } catch (error) {\n console.error('Error resuming sessions:', error)\n }\n }\n\n if (!resumedRef.current) {\n resumeSessions()\n resumedRef.current = true\n }\n }, [manager, resumedRef.current])\n\n return <WalletContext.Provider value={manager}>{children}</WalletContext.Provider>\n}\n"],"mappings":";AAAA,cAAc;;;ACEd,SAAS,gBAAgB;AACzB,YAAYA,YAAW;;;ACAvB,YAAY,WAAW;AAEvB,IAAM,gBAAsB,oBAAyC,MAAS;AAEvE,IAAM,mBAAmB,MAAM;AACpC,QAAM,UAAgB,iBAAW,aAAa;AAE9C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAEA,SAAO;AACT;AAOO,IAAM,iBAAiB,CAAC,EAAE,SAAS,SAAS,MAAwC;AACzF,QAAM,aAAmB,aAAO,KAAK;AAErC,EAAM,gBAAU,MAAM;AACpB,UAAM,iBAAiB,YAAY;AACjC,UAAI;AACF,cAAM,QAAQ,eAAe;AAAA,MAC/B,SAAS,OAAO;AACd,gBAAQ,MAAM,4BAA4B,KAAK;AAAA,MAC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iB;AAC1D,QAAM,gBAAgB,eAAe,WAAW;AAEhD,QAAM,gBAAgB,SAAS,QAAQ,OAAO,CAAC,UAAU,MAAM,aAAa;AAC5E,QAAM,mBAAmB,QAAQ;AAEjC,QAAM,mBAAmB,CACvB,UACA,eACA,gBACG;AACH,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,WAAO,aAAa,iBAAiB,UAAU,eAAe,WAAW;AAAA,EAC3E;AAEA,QAAM,oBAAoB,CAAC,UAAiC,kBAA4B;AACtF,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,WAAO,aAAa,kBAAkB,UAAU,aAAa;AAAA,EAC/D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["React"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@txnlab/use-wallet-react",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "React library for integrating Algorand wallets into decentralized applications",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"author": "Doug Richar <drichar@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "
|
|
9
|
+
"url": "https://github.com/txnlab/use-wallet.git",
|
|
10
10
|
"directory": "packages/use-wallet-react"
|
|
11
11
|
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"exports": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
12
17
|
"keywords": [
|
|
13
18
|
"algorand",
|
|
14
19
|
"wallet",
|
|
@@ -21,21 +26,31 @@
|
|
|
21
26
|
"kmd",
|
|
22
27
|
"react"
|
|
23
28
|
],
|
|
24
|
-
"author": "Doug Richar <drichar@gmail.com>",
|
|
25
|
-
"license": "MIT",
|
|
26
29
|
"files": [
|
|
27
30
|
"dist"
|
|
28
31
|
],
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@tanstack/react-store": "^0.3.1",
|
|
34
|
+
"@txnlab/use-wallet": "3.0.0-beta.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/react": "^18.2.45",
|
|
38
|
+
"algosdk": "^2.7.0",
|
|
39
|
+
"jsdom": "^24.0.0",
|
|
40
|
+
"react": "^18.2.0",
|
|
41
|
+
"react-dom": "^18.2.0",
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.2.2"
|
|
44
|
+
},
|
|
32
45
|
"peerDependencies": {
|
|
33
46
|
"@blockshake/defly-connect": "^1.1.6",
|
|
34
47
|
"@perawallet/connect": "^1.3.3",
|
|
35
48
|
"@walletconnect/modal": "^2.6.2",
|
|
36
49
|
"@walletconnect/sign-client": "^2.10.2",
|
|
37
50
|
"algosdk": "^2.6.0",
|
|
38
|
-
"
|
|
51
|
+
"lute-connect": "^1.1.3",
|
|
52
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
53
|
+
"react-dom": "^17.0.0 || ^18.0.0"
|
|
39
54
|
},
|
|
40
55
|
"peerDependenciesMeta": {
|
|
41
56
|
"@blockshake/defly-connect": {
|
|
@@ -49,28 +64,17 @@
|
|
|
49
64
|
},
|
|
50
65
|
"@walletconnect/sign-client": {
|
|
51
66
|
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"lute-connect": {
|
|
69
|
+
"optional": true
|
|
52
70
|
}
|
|
53
71
|
},
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"@tanstack/react-store": "^0.2.1",
|
|
56
|
-
"@txnlab/use-wallet-js": "3.0.0-alpha.11"
|
|
57
|
-
},
|
|
58
|
-
"devDependencies": {
|
|
59
|
-
"@types/react": "^18.2.45",
|
|
60
|
-
"algosdk": "^2.6.0",
|
|
61
|
-
"jsdom": "^23.0.1",
|
|
62
|
-
"react": "^18.2.0",
|
|
63
|
-
"react-dom": "^18.2.0",
|
|
64
|
-
"tsup": "^8.0.0",
|
|
65
|
-
"typescript": "^5.2.2"
|
|
66
|
-
},
|
|
67
72
|
"scripts": {
|
|
68
73
|
"build": "tsup",
|
|
69
74
|
"start": "tsup src/index.ts --watch",
|
|
70
75
|
"test": "vitest",
|
|
71
76
|
"test:watch": "vitest --watch",
|
|
72
77
|
"lint": "eslint -c '../../.eslintrc.json' '**/*.{js,ts}'",
|
|
73
|
-
"prettier": "prettier --check '**/*.{js,ts}'",
|
|
74
78
|
"typecheck": "tsc --noEmit"
|
|
75
79
|
}
|
|
76
80
|
}
|