@txnlab/use-wallet 2.1.1 → 2.1.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/README.md +31 -17
- package/dist/cjs/index.js +8 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +8 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,19 +138,19 @@ import React from 'react'
|
|
|
138
138
|
import { WalletProvider, useInitializeProviders, PROVIDER_ID } from '@txnlab/use-wallet'
|
|
139
139
|
|
|
140
140
|
const getDynamicDeflyWalletConnect = async () => {
|
|
141
|
-
const DeflyWalletConnect = (await import(
|
|
142
|
-
return DeflyWalletConnect
|
|
143
|
-
}
|
|
141
|
+
const DeflyWalletConnect = (await import('@blockshake/defly-connect')).DeflyWalletConnect
|
|
142
|
+
return DeflyWalletConnect
|
|
143
|
+
}
|
|
144
144
|
|
|
145
145
|
const getDynamicPeraWalletConnect = async () => {
|
|
146
|
-
const PeraWalletConnect = (await import(
|
|
147
|
-
return PeraWalletConnect
|
|
148
|
-
}
|
|
146
|
+
const PeraWalletConnect = (await import('@perawallet/connect')).PeraWalletConnect
|
|
147
|
+
return PeraWalletConnect
|
|
148
|
+
}
|
|
149
149
|
|
|
150
150
|
const getDynamicDaffiWalletConnect = async () => {
|
|
151
|
-
const DaffiWalletConnect = (await import(
|
|
152
|
-
return DaffiWalletConnect
|
|
153
|
-
}
|
|
151
|
+
const DaffiWalletConnect = (await import('@daffiwallet/connect')).DaffiWalletConnect
|
|
152
|
+
return DaffiWalletConnect
|
|
153
|
+
}
|
|
154
154
|
|
|
155
155
|
export default function App() {
|
|
156
156
|
const providers = useInitializeProviders({
|
|
@@ -170,7 +170,6 @@ export default function App() {
|
|
|
170
170
|
}
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
|
|
174
173
|
## The `useWallet` Hook
|
|
175
174
|
|
|
176
175
|
The `useWallet` hook is used to access wallet provider and account state, send unsigned transactions to be signed, and send signed transactions to the node from anywhere in your app. It returns an object with the following properties:
|
|
@@ -335,14 +334,10 @@ Here is an example of a signing and sending simple pay transaction using `signTr
|
|
|
335
334
|
```jsx
|
|
336
335
|
import React from 'react'
|
|
337
336
|
import algosdk from 'algosdk'
|
|
338
|
-
import {
|
|
339
|
-
|
|
340
|
-
DEFAULT_NODE_BASEURL,
|
|
341
|
-
DEFAULT_NODE_TOKEN,
|
|
342
|
-
DEFAULT_NODE_PORT
|
|
343
|
-
} from '@txnlab/use-wallet'
|
|
337
|
+
import { useWallet } from '@txnlab/use-wallet'
|
|
338
|
+
import { NODE_BASEURL, NODE_TOKEN, NODE_PORT } from '@/constants'
|
|
344
339
|
|
|
345
|
-
const algodClient = new algosdk.Algodv2(
|
|
340
|
+
const algodClient = new algosdk.Algodv2(NODE_TOKEN, NODE_BASEURL, NODE_PORT)
|
|
346
341
|
|
|
347
342
|
export default function Transact() {
|
|
348
343
|
const { activeAddress, signTransactions, sendTransactions } = useWallet()
|
|
@@ -558,6 +553,25 @@ const providers = useInitializeProviders({
|
|
|
558
553
|
})
|
|
559
554
|
```
|
|
560
555
|
|
|
556
|
+
The node configuration must match the network your app's algod client is connected to. The recommended approach is to define the node configuration variables as constants and pass them to both the `useInitializeProviders` hook and the `algosdk.Algodv2` constructor.
|
|
557
|
+
|
|
558
|
+
```jsx
|
|
559
|
+
import algosdk from 'algosdk'
|
|
560
|
+
import { NODE_BASEURL, NODE_TOKEN, NODE_PORT } from '@/constants'
|
|
561
|
+
|
|
562
|
+
const algodClient = new algosdk.Algodv2(NODE_TOKEN, NODE_BASEURL, NODE_PORT)
|
|
563
|
+
|
|
564
|
+
const providers = useInitializeProviders({
|
|
565
|
+
providers: [...],
|
|
566
|
+
nodeConfig: {
|
|
567
|
+
network: 'testnet',
|
|
568
|
+
nodeServer: NODE_BASEURL,
|
|
569
|
+
nodeToken: NODE_TOKEN,
|
|
570
|
+
nodePort: NODE_PORT
|
|
571
|
+
}
|
|
572
|
+
})
|
|
573
|
+
```
|
|
574
|
+
|
|
561
575
|
### Algosdk Static Import
|
|
562
576
|
|
|
563
577
|
By default, the providers dynamically import the `algosdk` peer dependency installed in your app, to reduce bundle size.
|
package/dist/cjs/index.js
CHANGED
|
@@ -2800,11 +2800,16 @@ var allClients = {
|
|
|
2800
2800
|
};
|
|
2801
2801
|
|
|
2802
2802
|
const initializeProviders = async (providers, nodeConfig, algosdkStatic) => {
|
|
2803
|
-
const initializedProviders = {};
|
|
2804
2803
|
if (typeof window === 'undefined') {
|
|
2805
2804
|
debugLog('Window object is not available, skipping initialization');
|
|
2806
|
-
return
|
|
2807
|
-
}
|
|
2805
|
+
return {};
|
|
2806
|
+
}
|
|
2807
|
+
// Set all providers to null to preserve order
|
|
2808
|
+
const initializedProviders = providers.reduce((acc, provider) => {
|
|
2809
|
+
const providerId = typeof provider === 'string' ? provider : provider.id;
|
|
2810
|
+
acc[providerId] = null;
|
|
2811
|
+
return acc;
|
|
2812
|
+
}, {});
|
|
2808
2813
|
const { network = DEFAULT_NETWORK, nodeServer = DEFAULT_NODE_BASEURL, nodePort = DEFAULT_NODE_PORT, nodeToken = DEFAULT_NODE_TOKEN } = nodeConfig || {};
|
|
2809
2814
|
const initClient = async (provider) => {
|
|
2810
2815
|
const { id, ...providerConfig } = typeof provider === 'string' ? { id: provider } : provider;
|