@txnlab/use-wallet 2.0.0-alpha.2 → 2.0.0-alpha.4

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/README.md CHANGED
@@ -511,8 +511,7 @@ import algosdk from 'algosdk'
511
511
  import { PROVIDER_ID, WalletProvider, useInitializeProviders } from '@txnlab/use-wallet'
512
512
  import { DeflyWalletConnect } from '@blockshake/defly-connect'
513
513
  import { PeraWalletConnect } from '@perawallet/connect'
514
- import SignClient from '@walletconnect/sign-client'
515
- import { WalletConnectModal } from '@walletconnect/modal'
514
+ import { Web3ModalSign } from '@web3modal/sign-html'
516
515
 
517
516
  export default function App() {
518
517
  const providers = useInitializeProviders({
@@ -521,8 +520,7 @@ export default function App() {
521
520
  { id: PROVIDER_ID.DEFLY, clientStatic: DeflyWalletConnect },
522
521
  {
523
522
  id: PROVIDER_ID.WALLETCONNECT,
524
- clientStatic: SignClient,
525
- modalStatic: WalletConnectModal,
523
+ clientStatic: Web3ModalSign,
526
524
  clientOptions: {
527
525
  projectId: '<YOUR_PROJECT_ID>',
528
526
  metadata: {
@@ -554,7 +552,7 @@ However, Algorand apps with `use-wallet` will be able to support the new protoco
554
552
 
555
553
  1. **Obtain a project ID** - You will need to obtain a project ID from [WalletConnect Cloud](https://cloud.walletconnect.com/). This is a simple process, and there is no waiting period. Every app will need its own unique project ID.
556
554
 
557
- 2. **Install peer dependencies** - Install `@walletconnect/sign-client` and `@walletconnect/modal`.
555
+ 2. **Install peer dependency** - Install `@web3modal/sign-html`.
558
556
 
559
557
  3. **Update provider configuration** - You will need to use a provider object to initialize WalletConnect, and pass your `clientOptions` as shown below
560
558
 
@@ -659,10 +657,10 @@ const providers = useInitializeProviders({
659
657
 
660
658
  ### WalletConnect provider
661
659
 
662
- The WalletConnect provider now supports WalletConnect 2.0. To continue supporting this provider, or to add support to your application, you must install the `@walletconnect/sign-client` and `@walletconnect/modal` packages.
660
+ The WalletConnect provider now supports WalletConnect 2.0. To continue supporting this provider, or to add support to your application, you must install the `@web3modal/sign-html` package.
663
661
 
664
662
  ```bash
665
- npm install @walletconnect/sign-client @walletconnect/modal
663
+ npm install @web3modal/sign-html
666
664
  ```
667
665
 
668
666
  The peer dependencies for WalletConnect 1.x should be uninstalled.
package/dist/cjs/index.js CHANGED
@@ -955,6 +955,11 @@ const useHydratedWalletStore = ((selector, compare) => {
955
955
  return hydrated ? store : selector(emptyState);
956
956
  });
957
957
 
958
+ const useDebugStore = create((set) => ({
959
+ debug: false,
960
+ setDebug: (debug) => set({ debug })
961
+ }));
962
+
958
963
  const ClientContext = require$$0.createContext(null);
959
964
  var clientStore = ClientContext.Provider;
960
965
 
@@ -1091,6 +1096,25 @@ class BaseClient {
1091
1096
  const ICON$8 = 'data:image/svg+xml;base64,' +
1092
1097
  'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNzcgMTg3Ij48cmVjdCB4PSItMTEuMzgiIHk9Ii0yNS45NyIgd2lkdGg9IjIwMC4wMiIgaGVpZ2h0PSIyMzEuNTMiIHN0eWxlPSJmaWxsOiNmZTU7Ii8+PHBhdGggZD0iTTk0LjA1LDU5LjYxYzIuMDUsOC40OCwxLjM2LDE1Ljk0LTEuNTUsMTYuNjYtMi45LC43Mi02LjkxLTUuNTctOC45Ni0xNC4wNS0yLjA1LTguNDgtMS4zNi0xNS45NCwxLjU1LTE2LjY2LDIuOS0uNzIsNi45MSw1LjU3LDguOTYsMTQuMDVaIiBzdHlsZT0iZmlsbDojMWMxYzFjOyIvPjxwYXRoIGQ9Ik0xMjcuODUsNjYuOWMtNC41My00LjgxLTEzLjU1LTMuNS0yMC4xNSwyLjkxLTYuNTksNi40MS04LjI2LDE1LjUtMy43MywyMC4zMSw0LjUzLDQuOCwxMy41NSwzLjUsMjAuMTUtMi45MXM4LjI2LTE1LjUsMy43My0yMC4zMVoiIHN0eWxlPSJmaWxsOiMxYzFjMWM7Ii8+PHBhdGggZD0iTTkxLjc5LDE0MC40N2MyLjktLjcyLDMuNDktOC42LDEuMzItMTcuNjEtMi4xNy05LTYuMjktMTUuNzEtOS4xOS0xNC45OS0yLjksLjcyLTMuNDksOC42LTEuMzIsMTcuNjEsMi4xNyw5LDYuMjksMTUuNzEsOS4xOSwxNC45OVoiIHN0eWxlPSJmaWxsOiMxYzFjMWM7Ii8+PHBhdGggZD0iTTYyLjIyLDcxLjNjOC4zNywyLjQ3LDE0LjQ4LDYuOCwxMy42Niw5LjY3LS44MywyLjg3LTguMjgsMy4yLTE2LjY1LC43My04LjM3LTIuNDctMTQuNDgtNi44LTEzLjY2LTkuNjcsLjgzLTIuODcsOC4yOC0zLjIsMTYuNjUtLjczWiIgc3R5bGU9ImZpbGw6IzFjMWMxYzsiLz48cGF0aCBkPSJNMTE2LjU0LDEwMy43NGM4Ljg4LDIuNjIsMTUuNDEsNy4wNywxNC41OSw5Ljk0LS44MywyLjg3LTguNywzLjA4LTE3LjU4LC40Ni04Ljg4LTIuNjItMTUuNDEtNy4wNy0xNC41OS05Ljk0LC44My0yLjg3LDguNy0zLjA4LDE3LjU4LS40NloiIHN0eWxlPSJmaWxsOiMxYzFjMWM7Ii8+PHBhdGggZD0iTTcxLjY0LDk3LjcxYy0yLjA4LTIuMTUtOC44OCwuOTgtMTUuMiw2Ljk5LTYuMzIsNi4wMS05Ljc2LDEyLjYzLTcuNjksMTQuNzgsMi4wOCwyLjE1LDguODgtLjk4LDE1LjItNi45OSw2LjMyLTYuMDEsOS43Ni0xMi42Myw3LjY5LTE0Ljc4WiIgc3R5bGU9ImZpbGw6IzFjMWMxYzsiLz48L3N2Zz4=';
1093
1098
 
1099
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1100
+ const debugLog = (...args) => {
1101
+ const { debug } = useDebugStore.getState();
1102
+ if (debug) {
1103
+ console.log('%c[USE-WALLET]', 'color: #FF602E; font-weight: bold;', ...args);
1104
+ }
1105
+ };
1106
+ const getProviderList = (providers) => {
1107
+ return providers
1108
+ .map((provider) => {
1109
+ if (typeof provider === 'string') {
1110
+ return provider;
1111
+ }
1112
+ return provider.id;
1113
+ })
1114
+ .map((id) => id.toUpperCase())
1115
+ .join(', ');
1116
+ };
1117
+
1094
1118
  class PeraWalletClient extends BaseClient {
1095
1119
  #client;
1096
1120
  clientOptions;
@@ -1110,13 +1134,14 @@ class PeraWalletClient extends BaseClient {
1110
1134
  };
1111
1135
  static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
1112
1136
  try {
1137
+ debugLog(`${exports.PROVIDER_ID.PERA.toUpperCase()} initializing...`);
1113
1138
  const PeraWalletConnect = clientStatic || (await import('@perawallet/connect')).PeraWalletConnect;
1114
1139
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1115
1140
  const algodClient = getAlgodClient(algosdk, algodOptions);
1116
1141
  const peraWallet = new PeraWalletConnect({
1117
1142
  ...(clientOptions && clientOptions)
1118
1143
  });
1119
- return new PeraWalletClient({
1144
+ const provider = new PeraWalletClient({
1120
1145
  metadata: PeraWalletClient.metadata,
1121
1146
  client: peraWallet,
1122
1147
  clientOptions,
@@ -1124,6 +1149,8 @@ class PeraWalletClient extends BaseClient {
1124
1149
  algodClient,
1125
1150
  network
1126
1151
  });
1152
+ debugLog(`${exports.PROVIDER_ID.PERA.toUpperCase()} initialized`, '✅');
1153
+ return provider;
1127
1154
  }
1128
1155
  catch (e) {
1129
1156
  console.error('Error initializing...', e);
@@ -1257,13 +1284,14 @@ class DaffiWalletClient extends BaseClient {
1257
1284
  };
1258
1285
  static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
1259
1286
  try {
1287
+ debugLog(`${exports.PROVIDER_ID.DAFFI.toUpperCase()} initializing...`);
1260
1288
  const DaffiWalletConnect = clientStatic || (await import('@daffiwallet/connect')).DaffiWalletConnect;
1261
1289
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1262
1290
  const algodClient = getAlgodClient(algosdk, algodOptions);
1263
1291
  const daffiWallet = new DaffiWalletConnect({
1264
1292
  ...(clientOptions ? clientOptions : { shouldShowSignTxnToast: false })
1265
1293
  });
1266
- return new DaffiWalletClient({
1294
+ const provider = new DaffiWalletClient({
1267
1295
  metadata: DaffiWalletClient.metadata,
1268
1296
  client: daffiWallet,
1269
1297
  clientOptions,
@@ -1271,6 +1299,8 @@ class DaffiWalletClient extends BaseClient {
1271
1299
  algodClient,
1272
1300
  network
1273
1301
  });
1302
+ debugLog(`${exports.PROVIDER_ID.DAFFI.toUpperCase()} initialized`, '✅');
1303
+ return provider;
1274
1304
  }
1275
1305
  catch (e) {
1276
1306
  console.error('Error initializing...', e);
@@ -1409,13 +1439,14 @@ class MyAlgoWalletClient extends BaseClient {
1409
1439
  };
1410
1440
  static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
1411
1441
  try {
1442
+ debugLog(`${exports.PROVIDER_ID.MYALGO.toUpperCase()} initializing...`);
1412
1443
  const MyAlgoConnect = clientStatic || (await import('@randlabs/myalgo-connect')).default;
1413
1444
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1414
1445
  const algodClient = getAlgodClient(algosdk, algodOptions);
1415
1446
  const myAlgo = new MyAlgoConnect({
1416
1447
  ...(clientOptions ? clientOptions : { disableLedgerNano: false })
1417
1448
  });
1418
- return new MyAlgoWalletClient({
1449
+ const provider = new MyAlgoWalletClient({
1419
1450
  metadata: MyAlgoWalletClient.metadata,
1420
1451
  client: myAlgo,
1421
1452
  clientOptions,
@@ -1423,6 +1454,8 @@ class MyAlgoWalletClient extends BaseClient {
1423
1454
  algodClient: algodClient,
1424
1455
  network
1425
1456
  });
1457
+ debugLog(`${exports.PROVIDER_ID.MYALGO.toUpperCase()} initialized`, '✅');
1458
+ return provider;
1426
1459
  }
1427
1460
  catch (e) {
1428
1461
  console.error('Error initializing...', e);
@@ -1511,19 +1544,22 @@ class DeflyWalletClient extends BaseClient {
1511
1544
  };
1512
1545
  static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
1513
1546
  try {
1547
+ debugLog(`${exports.PROVIDER_ID.DEFLY.toUpperCase()} initializing...`);
1514
1548
  const DeflyWalletConnect = clientStatic || (await import('@blockshake/defly-connect')).DeflyWalletConnect;
1515
1549
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1516
1550
  const algodClient = getAlgodClient(algosdk, algodOptions);
1517
1551
  const deflyWallet = new DeflyWalletConnect({
1518
1552
  ...(clientOptions && clientOptions)
1519
1553
  });
1520
- return new DeflyWalletClient({
1554
+ const provider = new DeflyWalletClient({
1521
1555
  metadata: DeflyWalletClient.metadata,
1522
1556
  client: deflyWallet,
1523
1557
  algosdk,
1524
1558
  algodClient,
1525
1559
  network
1526
1560
  });
1561
+ debugLog(`${exports.PROVIDER_ID.DEFLY.toUpperCase()} initialized`, '✅');
1562
+ return provider;
1527
1563
  }
1528
1564
  catch (e) {
1529
1565
  console.error('Error initializing...', e);
@@ -1657,13 +1693,14 @@ class ExodusClient extends BaseClient {
1657
1693
  };
1658
1694
  static async init({ clientOptions, algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
1659
1695
  try {
1696
+ debugLog(`${exports.PROVIDER_ID.EXODUS.toUpperCase()} initializing...`);
1660
1697
  if (typeof window == 'undefined' || window.exodus === undefined) {
1661
1698
  throw new Error('Exodus is not available.');
1662
1699
  }
1663
1700
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1664
1701
  const algodClient = getAlgodClient(algosdk, algodOptions);
1665
1702
  const exodus = window.exodus.algorand;
1666
- return new ExodusClient({
1703
+ const provider = new ExodusClient({
1667
1704
  metadata: ExodusClient.metadata,
1668
1705
  client: exodus,
1669
1706
  algosdk: algosdk,
@@ -1671,6 +1708,8 @@ class ExodusClient extends BaseClient {
1671
1708
  clientOptions: clientOptions || { onlyIfTrusted: false },
1672
1709
  network
1673
1710
  });
1711
+ debugLog(`${exports.PROVIDER_ID.EXODUS.toUpperCase()} initialized`, '✅');
1712
+ return provider;
1674
1713
  }
1675
1714
  catch (e) {
1676
1715
  console.warn(e);
@@ -1775,19 +1814,22 @@ class AlgoSignerClient extends BaseClient {
1775
1814
  };
1776
1815
  static async init({ algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
1777
1816
  try {
1817
+ debugLog(`${exports.PROVIDER_ID.ALGOSIGNER.toUpperCase()} initializing...`);
1778
1818
  if (typeof window == 'undefined' || window.algorand === undefined) {
1779
1819
  throw new Error('AlgoSigner is not available.');
1780
1820
  }
1781
1821
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1782
1822
  const algodClient = getAlgodClient(algosdk, algodOptions);
1783
1823
  const algosigner = window.algorand;
1784
- return new AlgoSignerClient({
1824
+ const provider = new AlgoSignerClient({
1785
1825
  metadata: AlgoSignerClient.metadata,
1786
1826
  client: algosigner,
1787
1827
  algosdk: algosdk,
1788
1828
  algodClient: algodClient,
1789
1829
  network
1790
1830
  });
1831
+ debugLog(`${exports.PROVIDER_ID.ALGOSIGNER.toUpperCase()} initialized`, '✅');
1832
+ return provider;
1791
1833
  }
1792
1834
  catch (e) {
1793
1835
  console.warn(e);
@@ -1899,6 +1941,19 @@ class AlgoSignerClient extends BaseClient {
1899
1941
  }
1900
1942
  }
1901
1943
 
1944
+ const ICON$2 = 'data:image/svg+xml;base64,' +
1945
+ 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgNDgwIDQ4MCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDgwIDQ4MDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiMzMzk2RkY7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTI2LjYsMTY4YzYyLjYtNjEuMywxNjQuMi02MS4zLDIyNi44LDBsNy41LDcuNGMzLjEsMy4xLDMuMSw4LDAsMTEuMWwtMjUuOCwyNS4yYy0xLjYsMS41LTQuMSwxLjUtNS43LDAKCWwtMTAuNC0xMC4yYy00My43LTQyLjgtMTE0LjUtNDIuOC0xNTguMiwwbC0xMS4xLDEwLjljLTEuNiwxLjUtNC4xLDEuNS01LjcsMGwtMjUuOC0yNS4yYy0zLjEtMy4xLTMuMS04LDAtMTEuMUwxMjYuNiwxNjh6CgkgTTQwNi43LDIyMC4ybDIyLjksMjIuNWMzLjEsMy4xLDMuMSw4LDAsMTEuMUwzMjYuMiwzNTUuMWMtMy4xLDMuMS04LjIsMy4xLTExLjMsMGwtNzMuNC03MS45Yy0wLjgtMC44LTIuMS0wLjgtMi44LDBsLTczLjQsNzEuOQoJYy0zLjEsMy4xLTguMiwzLjEtMTEuMywwTDUwLjMsMjUzLjhjLTMuMS0zLjEtMy4xLTgsMC0xMS4xbDIyLjktMjIuNWMzLjEtMy4xLDguMi0zLjEsMTEuMywwbDczLjQsNzEuOWMwLjgsMC44LDIuMSwwLjgsMi44LDAKCWw3My40LTcxLjljMy4xLTMuMSw4LjItMy4xLDExLjMsMGw3My40LDcxLjljMC44LDAuOCwyLjEsMC44LDIuOCwwbDczLjQtNzEuOUMzOTguNSwyMTcuMSw0MDMuNiwyMTcuMSw0MDYuNywyMjAuMkw0MDYuNywyMjAuMnoiLz4KPC9zdmc+Cg==';
1946
+ const DEFAULT_NETWORK = 'mainnet';
1947
+ const ALGORAND_CHAINS = {
1948
+ mainnet: 'algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k',
1949
+ testnet: 'algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe',
1950
+ betanet: 'algorand:mFgazF-2uRS1tMiL9dsj01hJGySEmPN2'
1951
+ };
1952
+
1953
+ const isPublicNetwork = (network) => {
1954
+ return network === 'betanet' || network === 'testnet' || network === 'mainnet';
1955
+ };
1956
+
1902
1957
  const getPayloadId = () => {
1903
1958
  const date = Date.now() * Math.pow(10, 3);
1904
1959
  const extra = Math.floor(Math.random() * Math.pow(10, 3));
@@ -1914,30 +1969,15 @@ const formatJsonRpcRequest = (method, params) => {
1914
1969
  };
1915
1970
  };
1916
1971
 
1917
- const isPublicNetwork = (network) => {
1918
- return network === 'betanet' || network === 'testnet' || network === 'mainnet';
1919
- };
1920
-
1921
- const ICON$2 = 'data:image/svg+xml;base64,' +
1922
- 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgNDgwIDQ4MCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDgwIDQ4MDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiMzMzk2RkY7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTI2LjYsMTY4YzYyLjYtNjEuMywxNjQuMi02MS4zLDIyNi44LDBsNy41LDcuNGMzLjEsMy4xLDMuMSw4LDAsMTEuMWwtMjUuOCwyNS4yYy0xLjYsMS41LTQuMSwxLjUtNS43LDAKCWwtMTAuNC0xMC4yYy00My43LTQyLjgtMTE0LjUtNDIuOC0xNTguMiwwbC0xMS4xLDEwLjljLTEuNiwxLjUtNC4xLDEuNS01LjcsMGwtMjUuOC0yNS4yYy0zLjEtMy4xLTMuMS04LDAtMTEuMUwxMjYuNiwxNjh6CgkgTTQwNi43LDIyMC4ybDIyLjksMjIuNWMzLjEsMy4xLDMuMSw4LDAsMTEuMUwzMjYuMiwzNTUuMWMtMy4xLDMuMS04LjIsMy4xLTExLjMsMGwtNzMuNC03MS45Yy0wLjgtMC44LTIuMS0wLjgtMi44LDBsLTczLjQsNzEuOQoJYy0zLjEsMy4xLTguMiwzLjEtMTEuMywwTDUwLjMsMjUzLjhjLTMuMS0zLjEtMy4xLTgsMC0xMS4xbDIyLjktMjIuNWMzLjEtMy4xLDguMi0zLjEsMTEuMywwbDczLjQsNzEuOWMwLjgsMC44LDIuMSwwLjgsMi44LDAKCWw3My40LTcxLjljMy4xLTMuMSw4LjItMy4xLDExLjMsMGw3My40LDcxLjljMC44LDAuOCwyLjEsMC44LDIuOCwwbDczLjQtNzEuOUMzOTguNSwyMTcuMSw0MDMuNiwyMTcuMSw0MDYuNywyMjAuMkw0MDYuNywyMjAuMnoiLz4KPC9zdmc+Cg==';
1923
- const DEFAULT_NETWORK = 'mainnet';
1924
- const ALGORAND_CHAINS = {
1925
- mainnet: 'algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k',
1926
- testnet: 'algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe',
1927
- betanet: 'algorand:mFgazF-2uRS1tMiL9dsj01hJGySEmPN2'
1928
- };
1929
-
1930
1972
  class WalletConnectClient extends BaseClient {
1931
1973
  #client;
1932
1974
  clientOptions;
1933
- #modal;
1934
1975
  network;
1935
1976
  chain;
1936
- constructor({ metadata, client, clientOptions, modal, algosdk, algodClient, network, chain }) {
1977
+ constructor({ metadata, client, clientOptions, algosdk, algodClient, network, chain }) {
1937
1978
  super(metadata, algosdk, algodClient);
1938
1979
  this.#client = client;
1939
1980
  this.clientOptions = clientOptions;
1940
- this.#modal = modal;
1941
1981
  this.network = network;
1942
1982
  this.chain = chain;
1943
1983
  this.metadata = WalletConnectClient.metadata;
@@ -1948,45 +1988,46 @@ class WalletConnectClient extends BaseClient {
1948
1988
  icon: ICON$2,
1949
1989
  isWalletConnect: true
1950
1990
  };
1951
- static async init({ clientOptions, algodOptions, clientStatic, modalStatic, modalOptions, algosdkStatic, network = DEFAULT_NETWORK }) {
1991
+ static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK }) {
1952
1992
  try {
1993
+ debugLog(`${exports.PROVIDER_ID.WALLETCONNECT.toUpperCase()} initializing...`);
1953
1994
  if (!isPublicNetwork(network)) {
1954
1995
  throw new Error(`WalletConnect only supports Algorand mainnet, testnet, and betanet. "${network}" is not supported.`);
1955
1996
  }
1997
+ if (!clientOptions) {
1998
+ throw new Error('WalletConnect clientOptions must be provided');
1999
+ }
1956
2000
  const chain = ALGORAND_CHAINS[network];
1957
- // Initialize sign client
1958
- const Client = clientStatic || (await import('@walletconnect/sign-client')).default;
1959
- const client = await Client.init(clientOptions);
1960
- // Initialize web3modal
1961
- const modalModule = modalStatic
1962
- ? { WalletConnectModal: modalStatic }
1963
- : await import('@walletconnect/modal');
1964
- const Web3Modal = modalModule.WalletConnectModal;
1965
- const modal = new Web3Modal({
1966
- explorerExcludedWalletIds: 'ALL',
1967
- ...modalOptions,
1968
- projectId: clientOptions?.projectId || '',
1969
- walletConnectVersion: 2
2001
+ const clientModule = clientStatic
2002
+ ? { Web3ModalSign: clientStatic }
2003
+ : await import('@web3modal/sign-html');
2004
+ const Client = clientModule.Web3ModalSign;
2005
+ // Initialize client
2006
+ const client = new Client({
2007
+ ...clientOptions,
2008
+ modalOptions: {
2009
+ explorerExcludedWalletIds: 'ALL',
2010
+ ...clientOptions.modalOptions
2011
+ }
1970
2012
  });
1971
2013
  // Initialize algod client
1972
2014
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1973
2015
  const algodClient = getAlgodClient(algosdk, algodOptions);
1974
- // Initialize wallet client
1975
- const walletClient = new WalletConnectClient({
2016
+ // Initialize provider client
2017
+ const provider = new WalletConnectClient({
1976
2018
  metadata: WalletConnectClient.metadata,
1977
2019
  client,
1978
2020
  clientOptions,
1979
- modal,
1980
2021
  algosdk,
1981
2022
  algodClient,
1982
2023
  network,
1983
2024
  chain
1984
2025
  });
1985
- walletClient.#subscribeToEvents();
1986
- return walletClient;
2026
+ debugLog(`${exports.PROVIDER_ID.WALLETCONNECT.toUpperCase()} initialized`, '✅');
2027
+ return provider;
1987
2028
  }
1988
2029
  catch (error) {
1989
- console.error('Error initializing', error);
2030
+ console.error('Error initializing WalletConnect client', error);
1990
2031
  return null;
1991
2032
  }
1992
2033
  }
@@ -1998,63 +2039,35 @@ class WalletConnectClient extends BaseClient {
1998
2039
  events: []
1999
2040
  }
2000
2041
  };
2001
- const { uri, approval } = await this.#client.connect({ requiredNamespaces });
2002
- if (uri) {
2003
- await this.#modal.openModal({ uri, standaloneChains: [this.chain] });
2004
- }
2005
- return new Promise((resolve, reject) => {
2006
- const unsubscribeModal = this.#modal.subscribeModal((state) => {
2007
- if (!state.open) {
2008
- unsubscribeModal();
2009
- reject(new Error('Modal closed'));
2010
- }
2011
- });
2012
- approval()
2013
- .then((session) => {
2014
- const { accounts } = session.namespaces.algorand;
2015
- resolve({
2016
- ...WalletConnectClient.metadata,
2017
- accounts: accounts.map((accountStr, index) => ({
2018
- name: `WalletConnect ${index + 1}`,
2019
- address: accountStr.split(':').pop(),
2020
- providerId: WalletConnectClient.metadata.id
2021
- }))
2022
- });
2023
- })
2024
- .catch((error) => {
2025
- reject(error);
2026
- })
2027
- .finally(() => {
2028
- unsubscribeModal();
2029
- this.#modal.closeModal();
2042
+ try {
2043
+ const session = await this.#client.connect({
2044
+ requiredNamespaces
2030
2045
  });
2031
- });
2046
+ const { accounts } = session.namespaces.algorand;
2047
+ return {
2048
+ ...WalletConnectClient.metadata,
2049
+ accounts: this.#mapAccounts(accounts)
2050
+ };
2051
+ }
2052
+ catch (error) {
2053
+ console.error('Error connecting to WalletConnect', error);
2054
+ throw error;
2055
+ }
2032
2056
  }
2033
- // eslint-disable-next-line @typescript-eslint/require-await
2034
2057
  async reconnect() {
2035
- const session = this.#getSession();
2058
+ const session = await this.#client.getSession();
2036
2059
  if (typeof session === 'undefined') {
2037
2060
  return null;
2038
2061
  }
2039
2062
  const { accounts } = session.namespaces.algorand;
2040
2063
  return {
2041
2064
  ...WalletConnectClient.metadata,
2042
- accounts: accounts.map((accountStr, index) => ({
2043
- name: `WalletConnect ${index + 1}`,
2044
- address: accountStr.split(':').pop(),
2045
- providerId: WalletConnectClient.metadata.id
2046
- }))
2065
+ accounts: this.#mapAccounts(accounts)
2047
2066
  };
2048
2067
  }
2049
2068
  async disconnect() {
2050
2069
  try {
2051
- if (typeof this.#client === 'undefined') {
2052
- throw new Error('WalletConnect is not initialized');
2053
- }
2054
- const session = this.#getSession();
2055
- if (typeof session === 'undefined') {
2056
- throw new Error('Session is not connected');
2057
- }
2070
+ const session = await this.#getSession();
2058
2071
  await this.#client.disconnect({
2059
2072
  topic: session.topic,
2060
2073
  // replicates getSdkError('USER_DISCONNECTED') from @walletconnect/utils
@@ -2068,27 +2081,49 @@ class WalletConnectClient extends BaseClient {
2068
2081
  console.error('Error disconnecting', error);
2069
2082
  }
2070
2083
  }
2071
- async signTransactions(connectedAccounts, txnGroups, indexesToSign, returnGroup = true) {
2072
- // If txnGroups is a nested array, flatten it
2084
+ async signTransactions(connectedAccounts, txnGroups, indexesToSign = [], returnGroup = true) {
2085
+ // Flatten transactions array if nested
2073
2086
  const transactions = Array.isArray(txnGroups[0])
2074
2087
  ? txnGroups.flatMap((txn) => txn)
2075
2088
  : txnGroups;
2076
- // Decode the transactions to access their properties.
2089
+ const { txnsToSign, signedIndexes } = this.#composeTransactions(transactions, connectedAccounts, indexesToSign);
2090
+ const request = formatJsonRpcRequest('algo_signTxn', [txnsToSign]);
2091
+ const session = await this.#getSession();
2092
+ const response = await this.#client.request({
2093
+ chainId: this.chain,
2094
+ topic: session.topic,
2095
+ request
2096
+ });
2097
+ // Check if the result is the same length as the transactions
2098
+ const lengthsMatch = response.length === transactions.length;
2099
+ // Join the signed transactions with the original group of transactions
2100
+ const signedTxns = transactions.reduce((acc, txn, i) => {
2101
+ if (signedIndexes.includes(i)) {
2102
+ const signedTxn = lengthsMatch ? response[i] : response.shift();
2103
+ signedTxn && acc.push(new Uint8Array(Buffer.from(signedTxn, 'base64')));
2104
+ }
2105
+ else if (returnGroup) {
2106
+ acc.push(txn);
2107
+ }
2108
+ return acc;
2109
+ }, []);
2110
+ return signedTxns;
2111
+ }
2112
+ #composeTransactions(transactions, connectedAccounts, indexesToSign) {
2113
+ // Decode the transactions
2077
2114
  const decodedTxns = transactions.map((txn) => {
2078
2115
  return this.algosdk.decodeObj(txn);
2079
2116
  });
2117
+ // Track signed transactions
2080
2118
  const signedIndexes = [];
2081
- // Marshal the transactions,
2082
- // and add the signers property if they shouldn't be signed.
2119
+ // Marshal the transactions into WalletConnect format
2083
2120
  const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
2084
2121
  const isSigned = 'txn' in txn;
2085
- if (indexesToSign && indexesToSign.length && indexesToSign.includes(i)) {
2086
- signedIndexes.push(i);
2087
- acc.push({
2088
- txn: Buffer.from(transactions[i]).toString('base64')
2089
- });
2090
- }
2091
- else if (!isSigned && connectedAccounts.includes(this.algosdk.encodeAddress(txn['snd']))) {
2122
+ const senderAccount = !isSigned
2123
+ ? this.algosdk.encodeAddress(txn['snd'])
2124
+ : this.algosdk.encodeAddress(txn.txn['snd']);
2125
+ const shouldSign = indexesToSign.includes(i) || (!isSigned && connectedAccounts.includes(senderAccount));
2126
+ if (shouldSign) {
2092
2127
  signedIndexes.push(i);
2093
2128
  acc.push({
2094
2129
  txn: Buffer.from(transactions[i]).toString('base64')
@@ -2104,51 +2139,21 @@ class WalletConnectClient extends BaseClient {
2104
2139
  }
2105
2140
  return acc;
2106
2141
  }, []);
2107
- const session = this.#getSession();
2142
+ return { txnsToSign, signedIndexes };
2143
+ }
2144
+ async #getSession() {
2145
+ const session = await this.#client.getSession();
2108
2146
  if (typeof session === 'undefined') {
2109
2147
  throw new Error('Session is not connected');
2110
2148
  }
2111
- const request = formatJsonRpcRequest('algo_signTxn', [txnsToSign]);
2112
- // Play an audio file to keep Wallet Connect's web socket open on iOS
2113
- // when the user goes into background mode.
2114
- // await this.keepWCAliveStart()
2115
- const response = await this.#client.request({
2116
- chainId: this.chain,
2117
- topic: session.topic,
2118
- request
2119
- });
2120
- // this.keepWCAliveStop()
2121
- // Check if the result is the same length as the transactions
2122
- const lengthsMatch = response.length === transactions.length;
2123
- // Join the newly signed transactions with the original group of transactions.
2124
- const signedTxns = transactions.reduce((acc, txn, i) => {
2125
- if (signedIndexes.includes(i)) {
2126
- const signedByUser = lengthsMatch ? response[i] : response.shift();
2127
- signedByUser && acc.push(new Uint8Array(Buffer.from(signedByUser, 'base64')));
2128
- }
2129
- else if (returnGroup) {
2130
- acc.push(txn);
2131
- }
2132
- return acc;
2133
- }, []);
2134
- return signedTxns;
2135
- }
2136
- #subscribeToEvents() {
2137
- if (typeof this.#client === 'undefined') {
2138
- throw new Error('WalletConnect is not initialized');
2139
- }
2140
- this.#client.on('session_event', (args) => {
2141
- console.log('EVENT', 'session_event', args);
2142
- });
2143
- this.#client.on('session_update', ({ topic, params }) => {
2144
- console.log('EVENT', 'session_update', { topic, params });
2145
- });
2146
- this.#client.on('session_delete', () => {
2147
- console.log('EVENT', 'session_delete');
2148
- });
2149
+ return session;
2149
2150
  }
2150
- #getSession() {
2151
- return this.#client.session.getAll().at(-1);
2151
+ #mapAccounts(accounts) {
2152
+ return accounts.map((accountStr, index) => ({
2153
+ name: `WalletConnect ${index + 1}`,
2154
+ address: accountStr.split(':').pop(),
2155
+ providerId: WalletConnectClient.metadata.id
2156
+ }));
2152
2157
  }
2153
2158
  }
2154
2159
 
@@ -2178,11 +2183,12 @@ class KMDWalletClient extends BaseClient {
2178
2183
  };
2179
2184
  static async init({ clientOptions, algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
2180
2185
  try {
2186
+ debugLog(`${exports.PROVIDER_ID.KMD.toUpperCase()} initializing...`);
2181
2187
  const { token = 'a'.repeat(64), host = 'http://localhost', port = '4002', wallet = 'unencrypted-default-wallet', password = '' } = clientOptions || {};
2182
2188
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
2183
2189
  const algodClient = getAlgodClient(algosdk, algodOptions);
2184
2190
  const kmdClient = new algosdk.Kmd(token, host, port);
2185
- return new KMDWalletClient({
2191
+ const provider = new KMDWalletClient({
2186
2192
  metadata: KMDWalletClient.metadata,
2187
2193
  password,
2188
2194
  wallet,
@@ -2191,6 +2197,8 @@ class KMDWalletClient extends BaseClient {
2191
2197
  algodClient: algodClient,
2192
2198
  network
2193
2199
  });
2200
+ debugLog(`${exports.PROVIDER_ID.KMD.toUpperCase()} initialized`, '✅');
2201
+ return provider;
2194
2202
  }
2195
2203
  catch (e) {
2196
2204
  console.error('Error initializing...', e);
@@ -2334,15 +2342,18 @@ class MnemonicWalletClient extends BaseClient {
2334
2342
  isWalletConnect: false
2335
2343
  };
2336
2344
  static async init({ algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
2345
+ debugLog(`${exports.PROVIDER_ID.MNEMONIC.toUpperCase()} initializing...`);
2337
2346
  try {
2338
2347
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
2339
2348
  const algodClient = getAlgodClient(algosdk, algodOptions);
2340
- return new MnemonicWalletClient({
2349
+ const provider = new MnemonicWalletClient({
2341
2350
  metadata: MnemonicWalletClient.metadata,
2342
2351
  algosdk: algosdk,
2343
2352
  algodClient: algodClient,
2344
2353
  network
2345
2354
  });
2355
+ debugLog(`${exports.PROVIDER_ID.MNEMONIC.toUpperCase()} initialized`);
2356
+ return provider;
2346
2357
  }
2347
2358
  catch (e) {
2348
2359
  console.error('Error initializing...', e);
@@ -2656,8 +2667,7 @@ function useWallet() {
2656
2667
  const initializeProviders = async (providers, nodeConfig, algosdkStatic) => {
2657
2668
  const initializedProviders = {};
2658
2669
  if (typeof window === 'undefined') {
2659
- // @todo add `debug: Boolean` option to enable/disable console logs
2660
- console.warn('Window object is not available, skipping initialization.');
2670
+ debugLog('Window object is not available, skipping initialization');
2661
2671
  return initializedProviders;
2662
2672
  }
2663
2673
  const { network = DEFAULT_NETWORK$1, nodeServer = DEFAULT_NODE_BASEURL, nodePort = DEFAULT_NODE_PORT, nodeToken = DEFAULT_NODE_TOKEN } = nodeConfig || {};
@@ -2672,14 +2682,15 @@ const initializeProviders = async (providers, nodeConfig, algosdkStatic) => {
2672
2682
  const client = await allClients[id].init(initParams);
2673
2683
  initializedProviders[id] = client;
2674
2684
  };
2675
- // Initialize default providers if `providers` is undefined or empty
2676
2685
  if (!providers || providers.length === 0) {
2686
+ debugLog('Initializing default providers:', getProviderList(DEFAULT_PROVIDERS));
2677
2687
  const initPromises = Object.keys(allClients)
2678
2688
  .filter((id) => DEFAULT_PROVIDERS.includes(id))
2679
2689
  .map((id) => initClient(id));
2680
2690
  await Promise.all(initPromises);
2681
2691
  }
2682
2692
  else {
2693
+ debugLog('Initializing custom providers:', getProviderList(providers));
2683
2694
  const initPromises = providers.map((provider) => initClient(provider));
2684
2695
  await Promise.all(initPromises);
2685
2696
  }
@@ -2717,7 +2728,10 @@ function encodeNFDTransactionsArray(transactionsArray) {
2717
2728
  });
2718
2729
  }
2719
2730
 
2720
- function useInitializeProviders({ providers = [], nodeConfig, algosdkStatic } = {}) {
2731
+ function useInitializeProviders({ providers = [], nodeConfig, algosdkStatic, debug = false } = {}) {
2732
+ // Enable debug mode
2733
+ const { setDebug } = useDebugStore();
2734
+ require$$0.useEffect(() => setDebug(debug), [debug, setDebug]);
2721
2735
  const [walletProviders, setWalletProviders] = require$$0.useState(null);
2722
2736
  require$$0.useEffect(() => {
2723
2737
  async function initializeAndConnect() {