@depay/web3-wallets-evm 15.7.0 → 15.9.0

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
@@ -14,6 +14,9 @@ npm install --save @depay/web3-wallets
14
14
  import { getWallets } from '@depay/web3-wallets'
15
15
 
16
16
  let wallets = await getWallets()
17
+
18
+ // display wallets, have user pick one:
19
+
17
20
  let wallet = wallets[0]
18
21
 
19
22
  wallet.name // MetaMask
@@ -78,7 +81,8 @@ import { getWallets } from '@depay/web3-wallets-solana'
78
81
 
79
82
  ### getWallets
80
83
 
81
- `getWallets`: Returns an array of available/connectable wallets.
84
+ `getWallets`: Returns an array of available/connectable wallets. Can wait up to 5 seconds because of checking existing WalletConnect connections.
85
+ Use `drip` to receive available wallets faster.
82
86
 
83
87
  ```javascript
84
88
  let availableWallets = await getWallets();
@@ -87,7 +91,7 @@ let availableWallets = await getWallets();
87
91
 
88
92
  ```javascript
89
93
  let availableWallets = await getWallets();
90
- // [] no wallets detected. (you can still try WalletConnect or WalletLink)
94
+ // [] no wallets detected. (you can still try have user connec via WalletConnect or WalletLink)
91
95
  ```
92
96
 
93
97
  ```javascript
@@ -108,6 +112,22 @@ if(availableWallets.length == 1) {
108
112
  }
109
113
  ```
110
114
 
115
+ #### drip
116
+
117
+ Pass a `drip` callback to `getWallets` to receive available wallet as soon as they are found, without waiting for all wallets to be checked:
118
+
119
+ ```javascript
120
+
121
+ getWallets({
122
+ drip: (wallet)=>{
123
+ setAvaialbleWallets(
124
+ availableWallets.concat([wallet])
125
+ )
126
+ }
127
+ })
128
+
129
+ ```
130
+
111
131
  ### Name
112
132
 
113
133
  `name:string`: Returns the name of the wallet.
@@ -355,7 +375,7 @@ let sentTransaction = await wallet.sendTransaction({
355
375
 
356
376
  If you need to sign an instruction (e.g. creating "throw away" accounts)
357
377
 
358
- you can set the `signers` of an instruction, which will be used to partially sign the transaction:
378
+ you can pass `signers` as part of the transaction passed to `sendTransaction`:
359
379
 
360
380
  ```javascript
361
381
  import { getProvider } from '@depay/web3-client'
@@ -378,11 +398,48 @@ let instruction = SystemProgram.createAccount({
378
398
  lamports: rent
379
399
  })
380
400
 
381
- instruction.signers = [keypair]
401
+ let sentTransaction = await wallet.sendTransaction({
402
+ blockchain: 'solana',
403
+ instructions: [instruction],
404
+ signers: [keypair],
405
+ sent: function(transaction){},
406
+ succeeded: function(transaction){},
407
+ failed: function(transaction, error){}
408
+ })
409
+ ```
410
+
411
+ ###### Solana: Address Lookup Tables
412
+
413
+ If you need to pass address lookup tables in order to reduce transaction size,
414
+
415
+ you can pass `alts` as part of the transaction passed to `sendTransaction`:
416
+
417
+ ```javascript
418
+ import { getProvider } from '@depay/web3-client'
419
+ import { Token } from '@depay/web3-tokens'
420
+ import { PublicKey, SystemProgram, Keypair } from '@depay/solana-web3.js'
421
+
422
+ const wallets = await getWallets()
423
+ const wallet = wallets[0]
424
+ const fromAddress = await wallet.account()
425
+ const provider = await getProvider('solana')
426
+ const keypair = Keypair.generate()
427
+ const account = keypair.publicKey.toString()
428
+ const rent = await provider.getMinimumBalanceForRentExemption(Token.solana.TOKEN_LAYOUT.span)
429
+
430
+ let instruction = SystemProgram.createAccount({
431
+ fromPubkey: new SolanaWeb3js.PublicKey(fromAddress),
432
+ newAccountPubkey: new SolanaWeb3js.PublicKey(wrappedAccount),
433
+ programId: new SolanaWeb3js.PublicKey(Web3Tokens.Token.solana.TOKEN_PROGRAM),
434
+ space: Web3Tokens.Token.solana.TOKEN_LAYOUT.span,
435
+ lamports: rent
436
+ })
382
437
 
383
438
  let sentTransaction = await wallet.sendTransaction({
384
439
  blockchain: 'solana',
385
440
  instructions: [instruction],
441
+ signers: [keypair],
442
+ alts: ['3sEm5YYxgLnP1Z11WXHSgScWqFMrATSNDgZcXAcB1w9A'],
386
443
  sent: function(transaction){},
387
444
  succeeded: function(transaction){},
388
445
  failed: function(transaction, error){}
@@ -41934,11 +41934,10 @@ const submitInstructions = async ({ transaction, wallet })=> {
41934
41934
  payerKey: fromPubkey,
41935
41935
  recentBlockhash,
41936
41936
  instructions: transaction.instructions,
41937
- }).compileToV0Message();
41937
+ }).compileToV0Message(transaction.alts ? transaction.alts : undefined);
41938
41938
  const transactionV0 = new VersionedTransaction(messageV0);
41939
- let signers = transaction.instructions.map((instruction)=>instruction.signers).filter(Boolean).flat();
41940
- if(signers.length) {
41941
- transactionV0.sign(Array.from(new Set(signers)));
41939
+ if(transaction.signers && transaction.signers.length) {
41940
+ transactionV0.sign(Array.from(new Set(transaction.signers)));
41942
41941
  }
41943
41942
  return window.solana.signAndSendTransaction(transactionV0)
41944
41943
  };
@@ -42271,7 +42270,10 @@ const getPlainInstance = ()=>{
42271
42270
  const isConnected = ()=>{
42272
42271
  return new Promise(async(resolve, reject)=>{
42273
42272
 
42274
- setTimeout(()=>{ resolve(false); }, 800);
42273
+ setTimeout(()=>{
42274
+ delete localStorage['walletconnect'];
42275
+ resolve(false);
42276
+ }, 5000);
42275
42277
 
42276
42278
  if(!localStorage['walletconnect'] || JSON.parse(localStorage['walletconnect']).handshakeTopic.length == 0) {
42277
42279
  delete localStorage['walletconnect'];
@@ -42757,10 +42759,14 @@ var wallets = {
42757
42759
  WalletLink
42758
42760
  };
42759
42761
 
42760
- const getWallets = async()=>{
42762
+ const getWallets = async(args)=>{
42763
+
42764
+ let drip = (args && typeof args.drip === 'function') ? args.drip : undefined;
42761
42765
 
42762
42766
  let availableWallets = await Promise.all(
42767
+
42763
42768
  Object.keys(wallets).map(
42769
+
42764
42770
  async(key)=>{
42765
42771
 
42766
42772
  let wallet = wallets[key];
@@ -42770,16 +42776,18 @@ const getWallets = async()=>{
42770
42776
 
42771
42777
  if(wallet.getConnectedInstance) {
42772
42778
  instance = await wallet.getConnectedInstance();
42779
+ if(drip) { drip(instance); }
42773
42780
  return instance
42774
42781
  } else {
42782
+ if(drip) { drip(wallet); }
42775
42783
  return new wallet
42776
- }
42784
+ }
42777
42785
  }
42778
42786
  }
42779
42787
  )
42780
42788
  );
42781
42789
 
42782
- return availableWallets.filter((wallet)=>wallet)
42790
+ return availableWallets.filter(Boolean)
42783
42791
  };
42784
42792
 
42785
42793
  const supported = [
package/dist/esm/index.js CHANGED
@@ -502,11 +502,10 @@ const submitInstructions = async ({ transaction, wallet })=> {
502
502
  payerKey: fromPubkey,
503
503
  recentBlockhash,
504
504
  instructions: transaction.instructions,
505
- }).compileToV0Message();
505
+ }).compileToV0Message(transaction.alts ? transaction.alts : undefined);
506
506
  const transactionV0 = new VersionedTransaction(messageV0);
507
- let signers = transaction.instructions.map((instruction)=>instruction.signers).filter(Boolean).flat();
508
- if(signers.length) {
509
- transactionV0.sign(Array.from(new Set(signers)));
507
+ if(transaction.signers && transaction.signers.length) {
508
+ transactionV0.sign(Array.from(new Set(transaction.signers)));
510
509
  }
511
510
  return window.solana.signAndSendTransaction(transactionV0)
512
511
  };
@@ -839,7 +838,10 @@ const getPlainInstance = ()=>{
839
838
  const isConnected = ()=>{
840
839
  return new Promise(async(resolve, reject)=>{
841
840
 
842
- setTimeout(()=>{ resolve(false); }, 800);
841
+ setTimeout(()=>{
842
+ delete localStorage['walletconnect'];
843
+ resolve(false);
844
+ }, 5000);
843
845
 
844
846
  if(!localStorage['walletconnect'] || JSON.parse(localStorage['walletconnect']).handshakeTopic.length == 0) {
845
847
  delete localStorage['walletconnect'];
@@ -1325,10 +1327,14 @@ var wallets = {
1325
1327
  WalletLink
1326
1328
  };
1327
1329
 
1328
- const getWallets = async()=>{
1330
+ const getWallets = async(args)=>{
1331
+
1332
+ let drip = (args && typeof args.drip === 'function') ? args.drip : undefined;
1329
1333
 
1330
1334
  let availableWallets = await Promise.all(
1335
+
1331
1336
  Object.keys(wallets).map(
1337
+
1332
1338
  async(key)=>{
1333
1339
 
1334
1340
  let wallet = wallets[key];
@@ -1338,16 +1344,18 @@ const getWallets = async()=>{
1338
1344
 
1339
1345
  if(wallet.getConnectedInstance) {
1340
1346
  instance = await wallet.getConnectedInstance();
1347
+ if(drip) { drip(instance); }
1341
1348
  return instance
1342
1349
  } else {
1350
+ if(drip) { drip(wallet); }
1343
1351
  return new wallet
1344
- }
1352
+ }
1345
1353
  }
1346
1354
  }
1347
1355
  )
1348
1356
  );
1349
1357
 
1350
- return availableWallets.filter((wallet)=>wallet)
1358
+ return availableWallets.filter(Boolean)
1351
1359
  };
1352
1360
 
1353
1361
  const supported = [
@@ -1243,11 +1243,10 @@ const submitInstructions = async ({ transaction, wallet })=> {
1243
1243
  payerKey: fromPubkey,
1244
1244
  recentBlockhash,
1245
1245
  instructions: transaction.instructions,
1246
- }).compileToV0Message();
1246
+ }).compileToV0Message(transaction.alts ? transaction.alts : undefined);
1247
1247
  const transactionV0 = new VersionedTransaction(messageV0);
1248
- let signers = transaction.instructions.map((instruction)=>instruction.signers).filter(Boolean).flat();
1249
- if(signers.length) {
1250
- transactionV0.sign(Array.from(new Set(signers)));
1248
+ if(transaction.signers && transaction.signers.length) {
1249
+ transactionV0.sign(Array.from(new Set(transaction.signers)));
1251
1250
  }
1252
1251
  return window.solana.signAndSendTransaction(transactionV0)
1253
1252
  };
@@ -1580,7 +1579,10 @@ const getPlainInstance = ()=>{
1580
1579
  const isConnected = ()=>{
1581
1580
  return new Promise(async(resolve, reject)=>{
1582
1581
 
1583
- setTimeout(()=>{ resolve(false); }, 800);
1582
+ setTimeout(()=>{
1583
+ delete localStorage['walletconnect'];
1584
+ resolve(false);
1585
+ }, 5000);
1584
1586
 
1585
1587
  if(!localStorage['walletconnect'] || JSON.parse(localStorage['walletconnect']).handshakeTopic.length == 0) {
1586
1588
  delete localStorage['walletconnect'];
@@ -2066,10 +2068,14 @@ var wallets = {
2066
2068
  WalletLink
2067
2069
  };
2068
2070
 
2069
- const getWallets = async()=>{
2071
+ const getWallets = async(args)=>{
2072
+
2073
+ let drip = (args && typeof args.drip === 'function') ? args.drip : undefined;
2070
2074
 
2071
2075
  let availableWallets = await Promise.all(
2076
+
2072
2077
  Object.keys(wallets).map(
2078
+
2073
2079
  async(key)=>{
2074
2080
 
2075
2081
  let wallet = wallets[key];
@@ -2079,16 +2085,18 @@ const getWallets = async()=>{
2079
2085
 
2080
2086
  if(wallet.getConnectedInstance) {
2081
2087
  instance = await wallet.getConnectedInstance();
2088
+ if(drip) { drip(instance); }
2082
2089
  return instance
2083
2090
  } else {
2091
+ if(drip) { drip(wallet); }
2084
2092
  return new wallet
2085
- }
2093
+ }
2086
2094
  }
2087
2095
  }
2088
2096
  )
2089
2097
  );
2090
2098
 
2091
- return availableWallets.filter((wallet)=>wallet)
2099
+ return availableWallets.filter(Boolean)
2092
2100
  };
2093
2101
 
2094
2102
  const supported = [
@@ -41938,11 +41938,10 @@
41938
41938
  payerKey: fromPubkey,
41939
41939
  recentBlockhash,
41940
41940
  instructions: transaction.instructions,
41941
- }).compileToV0Message();
41941
+ }).compileToV0Message(transaction.alts ? transaction.alts : undefined);
41942
41942
  const transactionV0 = new VersionedTransaction(messageV0);
41943
- let signers = transaction.instructions.map((instruction)=>instruction.signers).filter(Boolean).flat();
41944
- if(signers.length) {
41945
- transactionV0.sign(Array.from(new Set(signers)));
41943
+ if(transaction.signers && transaction.signers.length) {
41944
+ transactionV0.sign(Array.from(new Set(transaction.signers)));
41946
41945
  }
41947
41946
  return window.solana.signAndSendTransaction(transactionV0)
41948
41947
  };
@@ -42275,7 +42274,10 @@
42275
42274
  const isConnected = ()=>{
42276
42275
  return new Promise(async(resolve, reject)=>{
42277
42276
 
42278
- setTimeout(()=>{ resolve(false); }, 800);
42277
+ setTimeout(()=>{
42278
+ delete localStorage['walletconnect'];
42279
+ resolve(false);
42280
+ }, 5000);
42279
42281
 
42280
42282
  if(!localStorage['walletconnect'] || JSON.parse(localStorage['walletconnect']).handshakeTopic.length == 0) {
42281
42283
  delete localStorage['walletconnect'];
@@ -42761,10 +42763,14 @@
42761
42763
  WalletLink
42762
42764
  };
42763
42765
 
42764
- const getWallets = async()=>{
42766
+ const getWallets = async(args)=>{
42767
+
42768
+ let drip = (args && typeof args.drip === 'function') ? args.drip : undefined;
42765
42769
 
42766
42770
  let availableWallets = await Promise.all(
42771
+
42767
42772
  Object.keys(wallets).map(
42773
+
42768
42774
  async(key)=>{
42769
42775
 
42770
42776
  let wallet = wallets[key];
@@ -42774,16 +42780,18 @@
42774
42780
 
42775
42781
  if(wallet.getConnectedInstance) {
42776
42782
  instance = await wallet.getConnectedInstance();
42783
+ if(drip) { drip(instance); }
42777
42784
  return instance
42778
42785
  } else {
42786
+ if(drip) { drip(wallet); }
42779
42787
  return new wallet
42780
- }
42788
+ }
42781
42789
  }
42782
42790
  }
42783
42791
  )
42784
42792
  );
42785
42793
 
42786
- return availableWallets.filter((wallet)=>wallet)
42794
+ return availableWallets.filter(Boolean)
42787
42795
  };
42788
42796
 
42789
42797
  const supported = [
package/dist/umd/index.js CHANGED
@@ -505,11 +505,10 @@
505
505
  payerKey: fromPubkey,
506
506
  recentBlockhash,
507
507
  instructions: transaction.instructions,
508
- }).compileToV0Message();
508
+ }).compileToV0Message(transaction.alts ? transaction.alts : undefined);
509
509
  const transactionV0 = new solanaWeb3_js.VersionedTransaction(messageV0);
510
- let signers = transaction.instructions.map((instruction)=>instruction.signers).filter(Boolean).flat();
511
- if(signers.length) {
512
- transactionV0.sign(Array.from(new Set(signers)));
510
+ if(transaction.signers && transaction.signers.length) {
511
+ transactionV0.sign(Array.from(new Set(transaction.signers)));
513
512
  }
514
513
  return window.solana.signAndSendTransaction(transactionV0)
515
514
  };
@@ -842,7 +841,10 @@
842
841
  const isConnected = ()=>{
843
842
  return new Promise(async(resolve, reject)=>{
844
843
 
845
- setTimeout(()=>{ resolve(false); }, 800);
844
+ setTimeout(()=>{
845
+ delete localStorage['walletconnect'];
846
+ resolve(false);
847
+ }, 5000);
846
848
 
847
849
  if(!localStorage['walletconnect'] || JSON.parse(localStorage['walletconnect']).handshakeTopic.length == 0) {
848
850
  delete localStorage['walletconnect'];
@@ -1328,10 +1330,14 @@
1328
1330
  WalletLink
1329
1331
  };
1330
1332
 
1331
- const getWallets = async()=>{
1333
+ const getWallets = async(args)=>{
1334
+
1335
+ let drip = (args && typeof args.drip === 'function') ? args.drip : undefined;
1332
1336
 
1333
1337
  let availableWallets = await Promise.all(
1338
+
1334
1339
  Object.keys(wallets).map(
1340
+
1335
1341
  async(key)=>{
1336
1342
 
1337
1343
  let wallet = wallets[key];
@@ -1341,16 +1347,18 @@
1341
1347
 
1342
1348
  if(wallet.getConnectedInstance) {
1343
1349
  instance = await wallet.getConnectedInstance();
1350
+ if(drip) { drip(instance); }
1344
1351
  return instance
1345
1352
  } else {
1353
+ if(drip) { drip(wallet); }
1346
1354
  return new wallet
1347
- }
1355
+ }
1348
1356
  }
1349
1357
  }
1350
1358
  )
1351
1359
  );
1352
1360
 
1353
- return availableWallets.filter((wallet)=>wallet)
1361
+ return availableWallets.filter(Boolean)
1354
1362
  };
1355
1363
 
1356
1364
  const supported = [
@@ -1246,11 +1246,10 @@
1246
1246
  payerKey: fromPubkey,
1247
1247
  recentBlockhash,
1248
1248
  instructions: transaction.instructions,
1249
- }).compileToV0Message();
1249
+ }).compileToV0Message(transaction.alts ? transaction.alts : undefined);
1250
1250
  const transactionV0 = new solanaWeb3_js.VersionedTransaction(messageV0);
1251
- let signers = transaction.instructions.map((instruction)=>instruction.signers).filter(Boolean).flat();
1252
- if(signers.length) {
1253
- transactionV0.sign(Array.from(new Set(signers)));
1251
+ if(transaction.signers && transaction.signers.length) {
1252
+ transactionV0.sign(Array.from(new Set(transaction.signers)));
1254
1253
  }
1255
1254
  return window.solana.signAndSendTransaction(transactionV0)
1256
1255
  };
@@ -1583,7 +1582,10 @@
1583
1582
  const isConnected = ()=>{
1584
1583
  return new Promise(async(resolve, reject)=>{
1585
1584
 
1586
- setTimeout(()=>{ resolve(false); }, 800);
1585
+ setTimeout(()=>{
1586
+ delete localStorage['walletconnect'];
1587
+ resolve(false);
1588
+ }, 5000);
1587
1589
 
1588
1590
  if(!localStorage['walletconnect'] || JSON.parse(localStorage['walletconnect']).handshakeTopic.length == 0) {
1589
1591
  delete localStorage['walletconnect'];
@@ -2069,10 +2071,14 @@
2069
2071
  WalletLink
2070
2072
  };
2071
2073
 
2072
- const getWallets = async()=>{
2074
+ const getWallets = async(args)=>{
2075
+
2076
+ let drip = (args && typeof args.drip === 'function') ? args.drip : undefined;
2073
2077
 
2074
2078
  let availableWallets = await Promise.all(
2079
+
2075
2080
  Object.keys(wallets).map(
2081
+
2076
2082
  async(key)=>{
2077
2083
 
2078
2084
  let wallet = wallets[key];
@@ -2082,16 +2088,18 @@
2082
2088
 
2083
2089
  if(wallet.getConnectedInstance) {
2084
2090
  instance = await wallet.getConnectedInstance();
2091
+ if(drip) { drip(instance); }
2085
2092
  return instance
2086
2093
  } else {
2094
+ if(drip) { drip(wallet); }
2087
2095
  return new wallet
2088
- }
2096
+ }
2089
2097
  }
2090
2098
  }
2091
2099
  )
2092
2100
  );
2093
2101
 
2094
- return availableWallets.filter((wallet)=>wallet)
2102
+ return availableWallets.filter(Boolean)
2095
2103
  };
2096
2104
 
2097
2105
  const supported = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/web3-wallets-evm",
3
3
  "moduleName": "Web3Wallets",
4
- "version": "15.7.0",
4
+ "version": "15.9.0",
5
5
  "description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.",
6
6
  "main": "dist/umd/index.evm.js",
7
7
  "module": "dist/esm/index.evm.js",