@depay/web3-wallets-evm 14.6.5 → 14.8.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/dist/esm/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Blockchain } from '@depay/web3-blockchains';
2
2
  import { ethers } from 'ethers';
3
+ import { request as request$2, getProvider, estimate } from '@depay/web3-client';
3
4
  import { CONSTANTS } from '@depay/web3-constants';
4
5
  import { PublicKey, Transaction as Transaction$1, SystemProgram } from '@depay/solana-web3.js';
5
- import { getProvider, request as request$1, estimate } from '@depay/web3-client';
6
6
  import { WalletConnectClient } from '@depay/walletconnect-v1';
7
7
  import { Core, SignClient } from '@depay/walletconnect-v2';
8
8
  import { CoinbaseWalletSDK } from '@depay/coinbase-wallet-sdk';
@@ -213,7 +213,7 @@ let getWindow = () => {
213
213
 
214
214
  // MAKE SURE PROVIDER SUPPORT BATCH SIZE OF 99 BATCH REQUESTS!
215
215
  const ENDPOINTS = {
216
- ethereum: ['https://rpc.ankr.com/eth', 'https://eth-mainnet-public.unifra.io', 'https://ethereum.publicnode.com'],
216
+ ethereum: ['https://rpc.ankr.com/eth', 'https://eth.llamarpc.com', 'https://ethereum.publicnode.com'],
217
217
  bsc: ['https://bsc-dataseed.binance.org', 'https://bsc-dataseed1.ninicoin.io', 'https://bsc-dataseed3.defibit.io'],
218
218
  polygon: ['https://polygon-rpc.com', 'https://poly-rpc.gateway.pokt.network', 'https://matic-mainnet.chainstacklabs.com'],
219
219
  velas: ['https://mainnet.velas.com/rpc', 'https://evmexplorer.velas.com/rpc', 'https://explorer.velas.com/rpc'],
@@ -469,7 +469,7 @@ var requestEVM = async ({ blockchain, address, api, method, params, block }) =>
469
469
  }
470
470
  };
471
471
 
472
- let request = async function (url, options) {
472
+ let request$1 = async function (url, options) {
473
473
  let { blockchain, address, method } = parseUrl(url);
474
474
  let { api, params, cache: cache$1, block } = (typeof(url) == 'object' ? url : options) || {};
475
475
 
@@ -495,7 +495,7 @@ const sendTransaction$4 = async ({ transaction, wallet })=> {
495
495
  throw({ code: 'WRONG_NETWORK' })
496
496
  }
497
497
  await transaction.prepare({ wallet });
498
- let transactionCount = await request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
498
+ let transactionCount = await request$1({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
499
499
  transaction.nonce = transactionCount;
500
500
  let provider = new ethers.providers.Web3Provider(wallet.getProvider(), 'any');
501
501
  let signer = provider.getSigner(0);
@@ -681,6 +681,10 @@ class WindowEthereum {
681
681
  })
682
682
  }
683
683
 
684
+ transactionCount({ blockchain, address }) {
685
+ return request$2({ blockchain, method: 'transactionCount', address })
686
+ }
687
+
684
688
  async sign(message) {
685
689
  await this.account();
686
690
  let provider = new ethers.providers.Web3Provider(this.getProvider(), 'any');
@@ -1024,7 +1028,7 @@ class Safe {
1024
1028
  if(jsonResult && jsonResult.nonce) {
1025
1029
  transactionCount = jsonResult.nonce;
1026
1030
  } else {
1027
- transactionCount = parseInt((await request$1({
1031
+ transactionCount = parseInt((await request$2({
1028
1032
  blockchain: this.blockchain,
1029
1033
  address: this.address,
1030
1034
  api: [{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
@@ -1062,7 +1066,7 @@ const isSmartContractWallet = async(blockchain, address)=>{
1062
1066
  const identifySmartContractWallet = async (blockchain, address)=>{
1063
1067
  let name;
1064
1068
  try {
1065
- name = await request$1({
1069
+ name = await request$2({
1066
1070
  blockchain,
1067
1071
  address,
1068
1072
  api: [{ "constant": true, "inputs": [], "name": "NAME", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function"}],
@@ -1073,7 +1077,7 @@ const identifySmartContractWallet = async (blockchain, address)=>{
1073
1077
 
1074
1078
  let executor;
1075
1079
  try {
1076
- executor = await request$1({
1080
+ executor = await request$2({
1077
1081
  blockchain,
1078
1082
  address,
1079
1083
  api: [{ "constant": true, "inputs": [], "name": "staticCallExecutor", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function"}],
@@ -1107,7 +1111,7 @@ const sendTransaction$2 = async ({ transaction, wallet })=> {
1107
1111
  }
1108
1112
  await transaction.prepare({ wallet });
1109
1113
  const smartContractWallet = await getSmartContractWallet(transaction.blockchain, transaction.from);
1110
- const transactionCount = smartContractWallet ? await smartContractWallet.transactionCount() : await request$1({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
1114
+ let transactionCount = await wallet.transactionCount({ blockchain: transaction.blockchain, address: transaction.from });
1111
1115
  transaction.nonce = transactionCount;
1112
1116
  await submit$2({ transaction, wallet }).then((tx)=>{
1113
1117
  if (tx) {
@@ -1221,6 +1225,16 @@ const setConnectedInstance$2 = (value)=>{
1221
1225
  window[KEY$1] = value;
1222
1226
  };
1223
1227
 
1228
+ const getWalletConnectInstance = (connect)=>{
1229
+ return new WalletConnectClient({
1230
+ bridge: "https://walletconnect.depay.com",
1231
+ qrcodeModal: {
1232
+ open: async(uri)=>connect({ uri }),
1233
+ close: ()=>{},
1234
+ }
1235
+ })
1236
+ };
1237
+
1224
1238
  class WalletConnectV1 {
1225
1239
 
1226
1240
  static __initStatic() {this.info = {
@@ -1229,8 +1243,9 @@ class WalletConnectV1 {
1229
1243
  blockchains: ['ethereum', 'bsc', 'polygon', 'velas']
1230
1244
  };}
1231
1245
 
1232
- static __initStatic2() {this.isAvailable = ()=>{
1233
- return getConnectedInstance$2() != undefined
1246
+ static __initStatic2() {this.isAvailable = ()=>{
1247
+ let connector = getWalletConnectInstance(()=>{});
1248
+ return getConnectedInstance$2() != undefined || connector.connected
1234
1249
  };}
1235
1250
 
1236
1251
  constructor() {
@@ -1246,13 +1261,7 @@ class WalletConnectV1 {
1246
1261
  }
1247
1262
 
1248
1263
  newWalletConnectInstance(connect) {
1249
- let instance = new WalletConnectClient({
1250
- bridge: "https://walletconnect.depay.com",
1251
- qrcodeModal: {
1252
- open: async(uri)=>connect({ uri }),
1253
- close: ()=>{},
1254
- }
1255
- });
1264
+ let instance = getWalletConnectInstance(connect);
1256
1265
 
1257
1266
  instance.on("connect", (error, payload) => {
1258
1267
  if (error) { throw error }
@@ -1282,8 +1291,9 @@ class WalletConnectV1 {
1282
1291
  }
1283
1292
 
1284
1293
  async account() {
1285
- if(this.connectedAccounts == undefined) { return }
1286
- return this.connectedAccounts[0]
1294
+ if(!this.connector){ return }
1295
+ let accounts = await this.connector.sendCustomRequest({ method: 'eth_accounts' });
1296
+ if(accounts && accounts.length) { return ethers.utils.getAddress(accounts[0]) }
1287
1297
  }
1288
1298
 
1289
1299
  async connect(options) {
@@ -1291,7 +1301,6 @@ class WalletConnectV1 {
1291
1301
  if(_optionalChain$2([options, 'optionalAccess', _ => _.name])) { this.name = options.name; }
1292
1302
  if(_optionalChain$2([options, 'optionalAccess', _2 => _2.logo])) { this.logo = options.logo; }
1293
1303
  try {
1294
- window.localStorage.removeItem('walletconnect'); // https://github.com/WalletConnect/walletconnect-monorepo/issues/315
1295
1304
 
1296
1305
  this.connector = WalletConnectV1.instance;
1297
1306
 
@@ -1300,23 +1309,26 @@ class WalletConnectV1 {
1300
1309
  }
1301
1310
 
1302
1311
  if(this.connector.connected) {
1303
- await this.connector.killSession();
1304
- setConnectedInstance$2(undefined);
1305
- this.connector = this.newWalletConnectInstance(connect);
1306
- }
1307
1312
 
1308
- let { accounts, chainId } = await this.connector.connect();
1313
+ let account = await this.account();
1314
+ this.connectedChainId = await this.connector.sendCustomRequest({ method: 'eth_chainId' });
1309
1315
 
1310
- if(accounts instanceof Array && accounts.length) {
1311
- setConnectedInstance$2(this);
1312
- accounts = accounts.map((account)=>ethers.utils.getAddress(account));
1313
- this.connectedAccounts = accounts;
1314
- this.connectedChainId = chainId;
1315
-
1316
- return accounts[0]
1316
+ return account
1317
1317
  } else {
1318
- return
1318
+
1319
+ let { accounts, chainId } = await this.connector.connect();
1320
+
1321
+ if(accounts instanceof Array && accounts.length) {
1322
+ setConnectedInstance$2(this);
1323
+ accounts = accounts.map((account)=>ethers.utils.getAddress(account));
1324
+ this.connectedChainId = chainId;
1325
+
1326
+ return accounts[0]
1327
+ } else {
1328
+ return
1329
+ }
1319
1330
  }
1331
+
1320
1332
  } catch (error) {
1321
1333
  console.log('WALLETCONNECT ERROR', error);
1322
1334
  return undefined
@@ -1414,6 +1426,15 @@ class WalletConnectV1 {
1414
1426
  }
1415
1427
  }
1416
1428
 
1429
+ async transactionCount({ blockchain, address }) {
1430
+ const smartContractWallet = await getSmartContractWallet(blockchain, address);
1431
+ if(smartContractWallet) {
1432
+ return await smartContractWallet.transactionCount()
1433
+ } else {
1434
+ return await request$2({ blockchain, method: 'transactionCount', address })
1435
+ }
1436
+ }
1437
+
1417
1438
  async sign(message) {
1418
1439
  let address = await this.account();
1419
1440
  var params = [ethers.utils.toUtf8Bytes(message), address];
@@ -1435,7 +1456,7 @@ const sendTransaction$1 = async ({ transaction, wallet })=> {
1435
1456
  throw({ code: 'WRONG_NETWORK' })
1436
1457
  }
1437
1458
  await transaction.prepare({ wallet });
1438
- let transactionCount = await request$1({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
1459
+ let transactionCount = await request$2({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
1439
1460
  transaction.nonce = transactionCount;
1440
1461
  await submit$1({ transaction, wallet }).then(async (response)=>{
1441
1462
  if(typeof response == 'string') {
@@ -1913,6 +1934,10 @@ class WalletLink {
1913
1934
  return internalCallback
1914
1935
  }
1915
1936
 
1937
+ transactionCount({ blockchain, address }) {
1938
+ return request({ blockchain, method: 'transactionCount', address })
1939
+ }
1940
+
1916
1941
  async sign(message) {
1917
1942
  await this.account();
1918
1943
  let provider = new ethers.providers.Web3Provider(this.connector, 'any');