@kimafinance/kima-transaction-widget 1.2.76-beta.1 → 1.2.78-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/dist/index.js CHANGED
@@ -18,9 +18,9 @@ var walletAdapterBase = require('@solana/wallet-adapter-base');
18
18
  var satsConnect = require('sats-connect');
19
19
  var contracts = require('@ethersproject/contracts');
20
20
  var units = require('@ethersproject/units');
21
- var splToken = require('@solana/spl-token');
22
21
  var tronweb = require('tronweb');
23
22
  var ethers = require('ethers');
23
+ var splToken = require('@solana/spl-token');
24
24
  var BufferLayout = _interopDefault(require('buffer-layout'));
25
25
  var sha256$1 = _interopDefault(require('crypto-js/sha256.js'));
26
26
  var Base64 = _interopDefault(require('crypto-js/enc-base64.js'));
@@ -1887,7 +1887,6 @@ var SolanaWalletSelect = function SolanaWalletSelect() {
1887
1887
  var _useWallet = SolanaAdapter.useWallet(),
1888
1888
  selectedWallet = _useWallet.wallet,
1889
1889
  select = _useWallet.select;
1890
- console.log('selectedWallet: ', selectedWallet);
1891
1890
  var _useWallet2 = SolanaAdapter.useWallet(),
1892
1891
  wallets = _useWallet2.wallets;
1893
1892
  var _useMemo = React.useMemo(function () {
@@ -2466,167 +2465,6 @@ var ERC20ABI = {
2466
2465
  abi: abi
2467
2466
  };
2468
2467
 
2469
- function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId, associatedTokenProgramId) {
2470
- if (programId === void 0) {
2471
- programId = splToken.TOKEN_PROGRAM_ID;
2472
- }
2473
- if (associatedTokenProgramId === void 0) {
2474
- associatedTokenProgramId = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
2475
- }
2476
- var keys = [{
2477
- pubkey: payer,
2478
- isSigner: true,
2479
- isWritable: true
2480
- }, {
2481
- pubkey: associatedToken,
2482
- isSigner: false,
2483
- isWritable: true
2484
- }, {
2485
- pubkey: owner,
2486
- isSigner: false,
2487
- isWritable: false
2488
- }, {
2489
- pubkey: mint,
2490
- isSigner: false,
2491
- isWritable: false
2492
- }, {
2493
- pubkey: web3_js.SystemProgram.programId,
2494
- isSigner: false,
2495
- isWritable: false
2496
- }, {
2497
- pubkey: programId,
2498
- isSigner: false,
2499
- isWritable: false
2500
- }, {
2501
- pubkey: web3_js.SYSVAR_RENT_PUBKEY,
2502
- isSigner: false,
2503
- isWritable: false
2504
- }];
2505
- return new web3_js.TransactionInstruction({
2506
- keys: keys,
2507
- programId: associatedTokenProgramId,
2508
- data: Buffer.alloc(0)
2509
- });
2510
- }
2511
-
2512
- var getAccountInfo = function getAccountInfo(connection, address, commitment, programId) {
2513
- if (programId === void 0) {
2514
- programId = splToken.TOKEN_PROGRAM_ID;
2515
- }
2516
- try {
2517
- return Promise.resolve(connection.getAccountInfo(address, commitment)).then(function (info) {
2518
- if (!info) throw new Error('TokenAccountNotFoundError');
2519
- if (!info.owner.equals(programId)) throw new Error('TokenInvalidAccountOwnerError');
2520
- if (info.data.length != splToken.AccountLayout.span) throw new Error('TokenInvalidAccountSizeError');
2521
- var rawAccount = splToken.AccountLayout.decode(Buffer.from(info.data));
2522
- return {
2523
- address: address,
2524
- mint: rawAccount.mint,
2525
- owner: rawAccount.owner,
2526
- amount: rawAccount.amount,
2527
- delegate: rawAccount.delegateOption ? rawAccount.delegate : null,
2528
- delegatedAmount: rawAccount.delegatedAmount,
2529
- isInitialized: rawAccount.state !== AccountState.Uninitialized,
2530
- isFrozen: rawAccount.state === AccountState.Frozen,
2531
- isNative: !!rawAccount.isNativeOption,
2532
- rentExemptReserve: rawAccount.isNativeOption ? rawAccount.isNative : null,
2533
- closeAuthority: rawAccount.closeAuthorityOption ? rawAccount.closeAuthority : null
2534
- };
2535
- });
2536
- } catch (e) {
2537
- return Promise.reject(e);
2538
- }
2539
- };
2540
- var AccountState;
2541
- (function (AccountState) {
2542
- AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
2543
- AccountState[AccountState["Initialized"] = 1] = "Initialized";
2544
- AccountState[AccountState["Frozen"] = 2] = "Frozen";
2545
- })(AccountState || (AccountState = {}));
2546
-
2547
- var getAssociatedTokenAddress = function getAssociatedTokenAddress(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId) {
2548
- if (allowOwnerOffCurve === void 0) {
2549
- allowOwnerOffCurve = false;
2550
- }
2551
- if (programId === void 0) {
2552
- programId = splToken.TOKEN_PROGRAM_ID;
2553
- }
2554
- if (associatedTokenProgramId === void 0) {
2555
- associatedTokenProgramId = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
2556
- }
2557
- try {
2558
- if (!allowOwnerOffCurve && !web3_js.PublicKey.isOnCurve(owner.toBuffer())) throw new Error('TokenOwnerOffCurveError');
2559
- return Promise.resolve(web3_js.PublicKey.findProgramAddress([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId)).then(function (_ref) {
2560
- var address = _ref[0];
2561
- return address;
2562
- });
2563
- } catch (e) {
2564
- return Promise.reject(e);
2565
- }
2566
- };
2567
-
2568
- var getOrCreateAssociatedTokenAccount = function getOrCreateAssociatedTokenAccount(connection, payer, mint, owner, signTransaction, allowOwnerOffCurve, commitment, programId, associatedTokenProgramId) {
2569
- if (allowOwnerOffCurve === void 0) {
2570
- allowOwnerOffCurve = false;
2571
- }
2572
- if (programId === void 0) {
2573
- programId = splToken.TOKEN_PROGRAM_ID;
2574
- }
2575
- if (associatedTokenProgramId === void 0) {
2576
- associatedTokenProgramId = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
2577
- }
2578
- try {
2579
- return Promise.resolve(getAssociatedTokenAddress(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId)).then(function (associatedToken) {
2580
- var _exit = false;
2581
- function _temp4(_result) {
2582
- if (_exit) return _result;
2583
- if (!account.mint.equals(mint)) throw Error('TokenInvalidMintError');
2584
- if (!account.owner.equals(owner)) throw new Error('TokenInvalidOwnerError');
2585
- return account;
2586
- }
2587
- var account;
2588
- var _temp3 = _catch(function () {
2589
- return Promise.resolve(getAccountInfo(connection, associatedToken, commitment, programId)).then(function (_getAccountInfo) {
2590
- account = _getAccountInfo;
2591
- });
2592
- }, function (error) {
2593
- var err = error;
2594
- return function () {
2595
- if (err.message === 'TokenAccountNotFoundError' || err.message === 'TokenInvalidAccountOwnerError') {
2596
- var _temp2 = function _temp2() {
2597
- return Promise.resolve(getAccountInfo(connection, associatedToken, commitment, programId)).then(function (_getAccountInfo2) {
2598
- account = _getAccountInfo2;
2599
- });
2600
- };
2601
- var _temp = _catch(function () {
2602
- var transaction = new web3_js.Transaction().add(createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId, associatedTokenProgramId));
2603
- return Promise.resolve(connection.getRecentBlockhash()).then(function (blockHash) {
2604
- return Promise.resolve(payer).then(function (_payer) {
2605
- transaction.feePayer = _payer;
2606
- return Promise.resolve(blockHash.blockhash).then(function (_blockHash$blockhash) {
2607
- transaction.recentBlockhash = _blockHash$blockhash;
2608
- return Promise.resolve(signTransaction(transaction)).then(function (signed) {
2609
- return Promise.resolve(connection.sendRawTransaction(signed.serialize())).then(function (signature) {
2610
- return Promise.resolve(connection.confirmTransaction(signature)).then(function () {});
2611
- });
2612
- });
2613
- });
2614
- });
2615
- });
2616
- }, function () {});
2617
- return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
2618
- } else {
2619
- throw error;
2620
- }
2621
- }();
2622
- });
2623
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
2624
- });
2625
- } catch (e) {
2626
- return Promise.reject(e);
2627
- }
2628
- };
2629
-
2630
2468
  var tronWebTestnet = new tronweb.TronWeb({
2631
2469
  fullHost: 'https://api.nileex.io'
2632
2470
  });
@@ -2675,8 +2513,7 @@ function useBalance() {
2675
2513
  return selectedNetwork;
2676
2514
  }, [selectedNetwork, evmChainId, networkOption]);
2677
2515
  var _useSolanaWallet = SolanaAdapter.useWallet(),
2678
- solanaAddress = _useSolanaWallet.publicKey,
2679
- signTransaction = _useSolanaWallet.signTransaction;
2516
+ solanaAddress = _useSolanaWallet.publicKey;
2680
2517
  var _useTronWallet = tronwalletAdapterReactHooks.useWallet(),
2681
2518
  tronAddress = _useTronWallet.address;
2682
2519
  var btcAddress = reactRedux.useSelector(selectBitcoinAddress);
@@ -2705,8 +2542,8 @@ function useBalance() {
2705
2542
  if (!tokenAddress) return;
2706
2543
  var tronWeb = networkOption === exports.NetworkOptions.mainnet ? tronWebMainnet : tronWebTestnet;
2707
2544
  return _catch(function () {
2708
- function _temp6(_result4) {
2709
- return _exit ? _result4 : function () {
2545
+ function _temp6(_result3) {
2546
+ return _exit ? _result3 : function () {
2710
2547
  if (walletProvider) {
2711
2548
  var provider = new ethers.ethers.providers.Web3Provider(walletProvider);
2712
2549
  var signer = provider === null || provider === void 0 ? void 0 : provider.getSigner();
@@ -2722,11 +2559,10 @@ function useBalance() {
2722
2559
  }
2723
2560
  var _temp5 = function () {
2724
2561
  if (!isEVMChain(sourceChain)) {
2725
- var _temp4 = function _temp4(_result) {
2562
+ var _temp4 = function _temp4() {
2726
2563
  var _exit2 = false;
2727
- if (_exit) return _result;
2728
- function _temp2(_result2) {
2729
- return _exit2 ? _result2 : function () {
2564
+ function _temp2(_result) {
2565
+ return _exit2 ? _result : function () {
2730
2566
  if (sourceChain === exports.SupportNetworks.BTC && btcAddress) {
2731
2567
  return Promise.resolve(fetchWrapper.get(kimaBackendUrl + "/btc/balance?address=" + btcAddress)).then(function (btcInfo) {
2732
2568
  var balance = parseFloat(btcInfo.balance) / Math.pow(10, 8);
@@ -2752,14 +2588,10 @@ function useBalance() {
2752
2588
  };
2753
2589
  var _temp3 = function () {
2754
2590
  if (sourceChain === exports.SupportNetworks.SOLANA && solanaAddress && connection) {
2755
- var mint = new web3_js.PublicKey(tokenAddress);
2756
- return Promise.resolve(getOrCreateAssociatedTokenAccount(connection, solanaAddress, mint, solanaAddress, signTransaction)).then(function (fromTokenAccount) {
2757
- return Promise.resolve(connection.getParsedAccountInfo(fromTokenAccount.address)).then(function (accountInfo) {
2758
- var _accountInfo$value, _parsedAccountInfo$pa, _parsedAccountInfo$pa2, _parsedAccountInfo$pa3, _parsedAccountInfo$pa4, _parsedAccountInfo$pa5, _parsedAccountInfo$pa6;
2759
- var parsedAccountInfo = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$value = accountInfo.value) === null || _accountInfo$value === void 0 ? void 0 : _accountInfo$value.data;
2760
- setBalance(+units.formatUnits((_parsedAccountInfo$pa = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa === void 0 ? void 0 : (_parsedAccountInfo$pa2 = _parsedAccountInfo$pa.info) === null || _parsedAccountInfo$pa2 === void 0 ? void 0 : (_parsedAccountInfo$pa3 = _parsedAccountInfo$pa2.tokenAmount) === null || _parsedAccountInfo$pa3 === void 0 ? void 0 : _parsedAccountInfo$pa3.amount, (_parsedAccountInfo$pa4 = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa4 === void 0 ? void 0 : (_parsedAccountInfo$pa5 = _parsedAccountInfo$pa4.info) === null || _parsedAccountInfo$pa5 === void 0 ? void 0 : (_parsedAccountInfo$pa6 = _parsedAccountInfo$pa5.tokenAmount) === null || _parsedAccountInfo$pa6 === void 0 ? void 0 : _parsedAccountInfo$pa6.decimals));
2761
- _exit = true;
2762
- });
2591
+ return Promise.resolve(fetchWrapper.get(kimaBackendUrl + "/sol/balances/" + tokenAddress + "/" + solanaAddress.toBase58())).then(function (balanceInfo) {
2592
+ var amount = balanceInfo.amount,
2593
+ decimals = balanceInfo.decimals;
2594
+ setBalance(+units.formatUnits(amount, decimals));
2763
2595
  });
2764
2596
  }
2765
2597
  }();
@@ -7422,6 +7254,7 @@ function useAllowance(_ref) {
7422
7254
  walletProvider = _useWeb3ModalProvider.walletProvider;
7423
7255
  var selectedNetwork = reactRedux.useSelector(selectSourceChain);
7424
7256
  var errorHandler = reactRedux.useSelector(selectErrorHandler);
7257
+ var kimaBackendUrl = reactRedux.useSelector(selectBackendUrl);
7425
7258
  var dAppOption = reactRedux.useSelector(selectDappOption);
7426
7259
  var targetChain = reactRedux.useSelector(selectTargetChain);
7427
7260
  var feeDeduct = reactRedux.useSelector(selectFeeDeduct);
@@ -7526,15 +7359,12 @@ function useAllowance(_ref) {
7526
7359
  };
7527
7360
  var _temp2 = function () {
7528
7361
  if (solanaAddress && tokenAddress && connection) {
7529
- var mint = new web3_js.PublicKey(tokenAddress);
7530
- return Promise.resolve(getOrCreateAssociatedTokenAccount(connection, solanaAddress, mint, solanaAddress, signSolanaTransaction)).then(function (fromTokenAccount) {
7531
- return Promise.resolve(connection.getParsedAccountInfo(fromTokenAccount.address)).then(function (accountInfo) {
7532
- var _accountInfo$value, _parsedAccountInfo$pa, _parsedAccountInfo$pa2, _parsedAccountInfo$pa3, _parsedAccountInfo$pa4, _parsedAccountInfo$pa5, _parsedAccountInfo$pa6, _parsedAccountInfo$pa7, _parsedAccountInfo$pa8;
7533
- console.log('solana token account: ', accountInfo);
7534
- var parsedAccountInfo = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$value = accountInfo.value) === null || _accountInfo$value === void 0 ? void 0 : _accountInfo$value.data;
7535
- setDecimals((_parsedAccountInfo$pa = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa === void 0 ? void 0 : (_parsedAccountInfo$pa2 = _parsedAccountInfo$pa.info) === null || _parsedAccountInfo$pa2 === void 0 ? void 0 : (_parsedAccountInfo$pa3 = _parsedAccountInfo$pa2.tokenAmount) === null || _parsedAccountInfo$pa3 === void 0 ? void 0 : _parsedAccountInfo$pa3.decimals);
7536
- setAllowance(((_parsedAccountInfo$pa4 = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa4 === void 0 ? void 0 : (_parsedAccountInfo$pa5 = _parsedAccountInfo$pa4.info) === null || _parsedAccountInfo$pa5 === void 0 ? void 0 : _parsedAccountInfo$pa5.delegate) === targetAddress ? (_parsedAccountInfo$pa6 = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa6 === void 0 ? void 0 : (_parsedAccountInfo$pa7 = _parsedAccountInfo$pa6.info) === null || _parsedAccountInfo$pa7 === void 0 ? void 0 : (_parsedAccountInfo$pa8 = _parsedAccountInfo$pa7.delegatedAmount) === null || _parsedAccountInfo$pa8 === void 0 ? void 0 : _parsedAccountInfo$pa8.uiAmount : 0);
7537
- });
7362
+ return Promise.resolve(fetchWrapper.get(kimaBackendUrl + "/sol/allowance/" + tokenAddress + "/" + solanaAddress.toBase58())).then(function (allowanceInfo) {
7363
+ var tokenAllowance = allowanceInfo.allowance,
7364
+ decimals = allowanceInfo.decimals,
7365
+ spender = allowanceInfo.spender;
7366
+ setDecimals(decimals || 0);
7367
+ setAllowance(spender === targetAddress ? tokenAllowance : 0);
7538
7368
  });
7539
7369
  } else {
7540
7370
  var _temp6 = function () {
@@ -7550,7 +7380,6 @@ function useAllowance(_ref) {
7550
7380
  parsedDecimals = decimals;
7551
7381
  }
7552
7382
  return Promise.resolve(trc20Contract.allowance(tronAddress, targetAddress).call()).then(function (userAllowance) {
7553
- console.log(parsedDecimals, typeof parsedDecimals);
7554
7383
  setDecimals(parsedDecimals);
7555
7384
  setAllowance(+units.formatUnits(userAllowance, decimals));
7556
7385
  });
@@ -7585,49 +7414,45 @@ function useAllowance(_ref) {
7585
7414
  if (_exit2) return _result4;
7586
7415
  function _temp17(_result5) {
7587
7416
  if (_exit3) return _result5;
7588
- if (!signSolanaTransaction) return;
7417
+ if (!signSolanaTransaction || !solanaAddress) return;
7589
7418
  var _temp15 = _catch(function () {
7590
7419
  isCancel ? setCancellingApprove(true) : setApproving(true);
7591
- var mint = new web3_js.PublicKey(tokenAddress);
7592
- var toPublicKey = new web3_js.PublicKey(targetAddress);
7593
- return Promise.resolve(getOrCreateAssociatedTokenAccount(connection, solanaAddress, mint, solanaAddress, signSolanaTransaction)).then(function (fromTokenAccount) {
7594
- var transaction = new web3_js.Transaction().add(createApproveTransferInstruction(fromTokenAccount.address, toPublicKey, solanaAddress, isCancel ? 0 : +amountToShow * Math.pow(10, decimals != null ? decimals : 6), [], splToken.TOKEN_PROGRAM_ID));
7595
- return Promise.resolve(connection.getLatestBlockhash()).then(function (blockHash) {
7596
- transaction.feePayer = solanaAddress;
7597
- return Promise.resolve(blockHash.blockhash).then(function (_blockHash$blockhash) {
7598
- transaction.recentBlockhash = _blockHash$blockhash;
7599
- return Promise.resolve(signSolanaTransaction(transaction)).then(function (signed) {
7600
- return Promise.resolve(connection.sendRawTransaction(signed.serialize())).then(function () {
7601
- function _temp14() {
7602
- isCancel ? setCancellingApprove(false) : setApproving(false);
7603
- }
7604
- var accountInfo;
7605
- var allowAmount = 0;
7606
- var retryCount = 0;
7607
- var _temp13 = function () {
7608
- if (isCancel) {
7609
- var _temp12 = function _temp12() {
7610
- setAllowance(+amountToShow);
7611
- };
7612
- var _temp11 = _do(function () {
7613
- return Promise.resolve(connection.getParsedAccountInfo(fromTokenAccount.address)).then(function (_connection$getParsed) {
7614
- var _accountInfo, _accountInfo$value2, _parsedAccountInfo$pa9, _parsedAccountInfo$pa10, _parsedAccountInfo$pa11, _parsedAccountInfo$pa12, _parsedAccountInfo$pa13;
7615
- accountInfo = _connection$getParsed;
7616
- var parsedAccountInfo = (_accountInfo = accountInfo) === null || _accountInfo === void 0 ? void 0 : (_accountInfo$value2 = _accountInfo.value) === null || _accountInfo$value2 === void 0 ? void 0 : _accountInfo$value2.data;
7617
- allowAmount = ((_parsedAccountInfo$pa9 = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa9 === void 0 ? void 0 : (_parsedAccountInfo$pa10 = _parsedAccountInfo$pa9.info) === null || _parsedAccountInfo$pa10 === void 0 ? void 0 : _parsedAccountInfo$pa10.delegate) === targetAddress ? (_parsedAccountInfo$pa11 = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa11 === void 0 ? void 0 : (_parsedAccountInfo$pa12 = _parsedAccountInfo$pa11.info) === null || _parsedAccountInfo$pa12 === void 0 ? void 0 : (_parsedAccountInfo$pa13 = _parsedAccountInfo$pa12.delegatedAmount) === null || _parsedAccountInfo$pa13 === void 0 ? void 0 : _parsedAccountInfo$pa13.uiAmount : 0;
7618
- return Promise.resolve(sleep(1000)).then(function () {});
7619
- });
7620
- }, function () {
7621
- return allowAmount < +amountToShow || retryCount++ < 5;
7622
- });
7623
- return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11);
7624
- } else {
7625
- setAllowance(0);
7626
- }
7627
- }();
7628
- return _temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13);
7629
- });
7630
- });
7420
+ return Promise.resolve(fetchWrapper.get(kimaBackendUrl + "/sol/info/" + tokenAddress + "/" + solanaAddress.toBase58())).then(function (tokenInfo) {
7421
+ var tokenAccount = tokenInfo.tokenAccount,
7422
+ blockHash = tokenInfo.blockHash;
7423
+ var toPublicKey = new web3_js.PublicKey(targetAddress);
7424
+ var tokenAccountPublicKey = new web3_js.PublicKey(tokenAccount);
7425
+ var transaction = new web3_js.Transaction().add(createApproveTransferInstruction(tokenAccountPublicKey, toPublicKey, solanaAddress, isCancel ? 0 : +amountToShow * Math.pow(10, decimals != null ? decimals : 6), [], splToken.TOKEN_PROGRAM_ID));
7426
+ transaction.feePayer = solanaAddress;
7427
+ transaction.recentBlockhash = blockHash;
7428
+ return Promise.resolve(signSolanaTransaction(transaction)).then(function (signed) {
7429
+ return Promise.resolve(fetchWrapper.post(kimaBackendUrl + "/sol/send", JSON.stringify({
7430
+ transaction: signed.serialize()
7431
+ }))).then(function () {
7432
+ function _temp14() {
7433
+ isCancel ? setCancellingApprove(false) : setApproving(false);
7434
+ }
7435
+ var allowAmount = 0;
7436
+ var retryCount = 0;
7437
+ var _temp13 = function () {
7438
+ if (!isCancel) {
7439
+ var _temp12 = function _temp12() {
7440
+ setAllowance(allowAmount);
7441
+ };
7442
+ var _temp11 = _do(function () {
7443
+ return Promise.resolve(fetchWrapper.get(kimaBackendUrl + "/sol/allowance/" + tokenAddress + "/" + solanaAddress.toBase58())).then(function (allowanceInfo) {
7444
+ allowAmount = allowanceInfo.allowance;
7445
+ return Promise.resolve(sleep(2000)).then(function () {});
7446
+ });
7447
+ }, function () {
7448
+ return allowAmount < +amountToShow && retryCount++ < 20;
7449
+ });
7450
+ return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11);
7451
+ } else {
7452
+ setAllowance(0);
7453
+ }
7454
+ }();
7455
+ return _temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13);
7631
7456
  });
7632
7457
  });
7633
7458
  });
@@ -7720,31 +7545,26 @@ function useAllowance(_ref) {
7720
7545
  }
7721
7546
 
7722
7547
  function useGetSolBalance() {
7723
- var networkOption = reactRedux.useSelector(selectNetworkOption);
7724
7548
  var _useState = React.useState(0),
7725
7549
  solBalance = _useState[0],
7726
7550
  setSolBalance = _useState[1];
7727
7551
  var _useWallet = SolanaAdapter.useWallet(),
7728
7552
  publicKey = _useWallet.publicKey;
7729
- var cluster = React.useMemo(function () {
7730
- return networkOption === 'testnet' ? 'devnet' : 'mainnet-beta';
7731
- }, [networkOption]);
7732
- var connection = React.useMemo(function () {
7733
- return new web3_js.Connection(web3_js.clusterApiUrl(cluster), 'confirmed');
7734
- }, [cluster]);
7553
+ var _useConnection = SolanaAdapter.useConnection(),
7554
+ connection = _useConnection.connection;
7555
+ var kimaBackendUrl = reactRedux.useSelector(selectBackendUrl);
7735
7556
  React.useEffect(function () {
7736
7557
  var fetchBalance = function fetchBalance() {
7737
7558
  try {
7738
7559
  var _temp2 = function () {
7739
7560
  if (publicKey) {
7740
7561
  var _temp = _catch(function () {
7741
- return Promise.resolve(connection.getBalance(publicKey)).then(function (_connection$getBalanc) {
7742
- var balance = _connection$getBalanc / web3_js.LAMPORTS_PER_SOL;
7743
- console.log('SOL balance:', balance);
7744
- setSolBalance(balance);
7562
+ return Promise.resolve(fetchWrapper.get(kimaBackendUrl + "/sol/" + (publicKey === null || publicKey === void 0 ? void 0 : publicKey.toBase58()))).then(function (solBalanceInfo) {
7563
+ var solBalance = solBalanceInfo.solBalance;
7564
+ setSolBalance(solBalance);
7745
7565
  });
7746
7566
  }, function (error) {
7747
- console.error('Error fetching SOL balance:', error);
7567
+ console.error('Error fetching SOL balance from backend: ', error);
7748
7568
  });
7749
7569
  if (_temp && _temp.then) return _temp.then(function () {});
7750
7570
  }
@@ -8142,7 +7962,7 @@ function output(out, instance) {
8142
7962
  exports.output = output;
8143
7963
  const assert = { number, bool, bytes, hash, exists, output };
8144
7964
  exports.default = assert;
8145
-
7965
+ //# sourceMappingURL=_assert.js.map
8146
7966
  });
8147
7967
 
8148
7968
  unwrapExports(_assert);
@@ -8151,7 +7971,7 @@ var crypto = createCommonjsModule(function (module, exports) {
8151
7971
  Object.defineProperty(exports, "__esModule", { value: true });
8152
7972
  exports.crypto = void 0;
8153
7973
  exports.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
8154
-
7974
+ //# sourceMappingURL=crypto.js.map
8155
7975
  });
8156
7976
 
8157
7977
  unwrapExports(crypto);
@@ -8353,7 +8173,7 @@ function randomBytes(bytesLength = 32) {
8353
8173
  throw new Error('crypto.getRandomValues must be defined');
8354
8174
  }
8355
8175
  exports.randomBytes = randomBytes;
8356
-
8176
+ //# sourceMappingURL=utils.js.map
8357
8177
  });
8358
8178
 
8359
8179
  unwrapExports(utils);
@@ -8475,7 +8295,7 @@ class SHA2 extends utils.Hash {
8475
8295
  }
8476
8296
  }
8477
8297
  exports.SHA2 = SHA2;
8478
-
8298
+ //# sourceMappingURL=_sha2.js.map
8479
8299
  });
8480
8300
 
8481
8301
  unwrapExports(_sha2);
@@ -8608,7 +8428,7 @@ class SHA224 extends SHA256 {
8608
8428
  */
8609
8429
  exports.sha256 = (0, utils.wrapConstructor)(() => new SHA256());
8610
8430
  exports.sha224 = (0, utils.wrapConstructor)(() => new SHA224());
8611
-
8431
+ //# sourceMappingURL=sha256.js.map
8612
8432
  });
8613
8433
 
8614
8434
  unwrapExports(sha256);
@@ -8991,8 +8811,6 @@ const isFormData = (thing) => {
8991
8811
  */
8992
8812
  const isURLSearchParams = kindOfTest('URLSearchParams');
8993
8813
 
8994
- const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
8995
-
8996
8814
  /**
8997
8815
  * Trim excess whitespace off the beginning and end of a string
8998
8816
  *
@@ -9381,7 +9199,8 @@ const toObjectSet = (arrayOrString, delimiter) => {
9381
9199
  const noop = () => {};
9382
9200
 
9383
9201
  const toFiniteNumber = (value, defaultValue) => {
9384
- return value != null && Number.isFinite(value = +value) ? value : defaultValue;
9202
+ value = +value;
9203
+ return Number.isFinite(value) ? value : defaultValue;
9385
9204
  };
9386
9205
 
9387
9206
  const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
@@ -9451,36 +9270,6 @@ const isAsyncFn = kindOfTest('AsyncFunction');
9451
9270
  const isThenable = (thing) =>
9452
9271
  thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
9453
9272
 
9454
- // original code
9455
- // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
9456
-
9457
- const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
9458
- if (setImmediateSupported) {
9459
- return setImmediate;
9460
- }
9461
-
9462
- return postMessageSupported ? ((token, callbacks) => {
9463
- _global.addEventListener("message", ({source, data}) => {
9464
- if (source === _global && data === token) {
9465
- callbacks.length && callbacks.shift()();
9466
- }
9467
- }, false);
9468
-
9469
- return (cb) => {
9470
- callbacks.push(cb);
9471
- _global.postMessage(token, "*");
9472
- }
9473
- })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
9474
- })(
9475
- typeof setImmediate === 'function',
9476
- isFunction(_global.postMessage)
9477
- );
9478
-
9479
- const asap = typeof queueMicrotask !== 'undefined' ?
9480
- queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
9481
-
9482
- // *********************
9483
-
9484
9273
  var utils$1 = {
9485
9274
  isArray,
9486
9275
  isArrayBuffer,
@@ -9492,10 +9281,6 @@ var utils$1 = {
9492
9281
  isBoolean,
9493
9282
  isObject,
9494
9283
  isPlainObject,
9495
- isReadableStream,
9496
- isRequest,
9497
- isResponse,
9498
- isHeaders,
9499
9284
  isUndefined,
9500
9285
  isDate,
9501
9286
  isFile,
@@ -9536,9 +9321,7 @@ var utils$1 = {
9536
9321
  isSpecCompliantForm,
9537
9322
  toJSONObject,
9538
9323
  isAsyncFn,
9539
- isThenable,
9540
- setImmediate: _setImmediate,
9541
- asap
9324
+ isThenable
9542
9325
  };
9543
9326
 
9544
9327
  /**
@@ -9566,10 +9349,7 @@ function AxiosError(message, code, config, request, response) {
9566
9349
  code && (this.code = code);
9567
9350
  config && (this.config = config);
9568
9351
  request && (this.request = request);
9569
- if (response) {
9570
- this.response = response;
9571
- this.status = response.status ? response.status : null;
9572
- }
9352
+ response && (this.response = response);
9573
9353
  }
9574
9354
 
9575
9355
  utils$1.inherits(AxiosError, Error, {
@@ -9589,7 +9369,7 @@ utils$1.inherits(AxiosError, Error, {
9589
9369
  // Axios
9590
9370
  config: utils$1.toJSONObject(this.config),
9591
9371
  code: this.code,
9592
- status: this.status
9372
+ status: this.response && this.response.status ? this.response.status : null
9593
9373
  };
9594
9374
  }
9595
9375
  });
@@ -10055,8 +9835,6 @@ var platform = {
10055
9835
 
10056
9836
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
10057
9837
 
10058
- const _navigator = typeof navigator === 'object' && navigator || undefined;
10059
-
10060
9838
  /**
10061
9839
  * Determine if we're running in a standard browser environment
10062
9840
  *
@@ -10074,8 +9852,10 @@ const _navigator = typeof navigator === 'object' && navigator || undefined;
10074
9852
  *
10075
9853
  * @returns {boolean}
10076
9854
  */
10077
- const hasStandardBrowserEnv = hasBrowserEnv &&
10078
- (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
9855
+ const hasStandardBrowserEnv = (
9856
+ (product) => {
9857
+ return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
9858
+ })(typeof navigator !== 'undefined' && navigator.product);
10079
9859
 
10080
9860
  /**
10081
9861
  * Determine if we're running in a standard browser webWorker environment
@@ -10095,15 +9875,11 @@ const hasStandardBrowserWebWorkerEnv = (() => {
10095
9875
  );
10096
9876
  })();
10097
9877
 
10098
- const origin = hasBrowserEnv && window.location.href || 'http://localhost';
10099
-
10100
9878
  var utils$2 = {
10101
9879
  __proto__: null,
10102
9880
  hasBrowserEnv: hasBrowserEnv,
10103
9881
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
10104
- hasStandardBrowserEnv: hasStandardBrowserEnv,
10105
- navigator: _navigator,
10106
- origin: origin
9882
+ hasStandardBrowserEnv: hasStandardBrowserEnv
10107
9883
  };
10108
9884
 
10109
9885
  var platform$1 = {
@@ -10243,7 +10019,7 @@ const defaults = {
10243
10019
 
10244
10020
  transitional: transitionalDefaults,
10245
10021
 
10246
- adapter: ['xhr', 'http', 'fetch'],
10022
+ adapter: ['xhr', 'http'],
10247
10023
 
10248
10024
  transformRequest: [function transformRequest(data, headers) {
10249
10025
  const contentType = headers.getContentType() || '';
@@ -10264,8 +10040,7 @@ const defaults = {
10264
10040
  utils$1.isBuffer(data) ||
10265
10041
  utils$1.isStream(data) ||
10266
10042
  utils$1.isFile(data) ||
10267
- utils$1.isBlob(data) ||
10268
- utils$1.isReadableStream(data)
10043
+ utils$1.isBlob(data)
10269
10044
  ) {
10270
10045
  return data;
10271
10046
  }
@@ -10308,10 +10083,6 @@ const defaults = {
10308
10083
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
10309
10084
  const JSONRequested = this.responseType === 'json';
10310
10085
 
10311
- if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
10312
- return data;
10313
- }
10314
-
10315
10086
  if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
10316
10087
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
10317
10088
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
@@ -10513,10 +10284,6 @@ class AxiosHeaders {
10513
10284
  setHeaders(header, valueOrRewrite);
10514
10285
  } else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
10515
10286
  setHeaders(parseHeaders(header), valueOrRewrite);
10516
- } else if (utils$1.isHeaders(header)) {
10517
- for (const [key, value] of header.entries()) {
10518
- setHeader(value, key, rewrite);
10519
- }
10520
10287
  } else {
10521
10288
  header != null && setHeader(valueOrRewrite, header, rewrite);
10522
10289
  }
@@ -10782,170 +10549,113 @@ function settle(resolve, reject, response) {
10782
10549
  }
10783
10550
  }
10784
10551
 
10785
- function parseProtocol(url) {
10786
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
10787
- return match && match[1] || '';
10788
- }
10552
+ var cookies = platform$1.hasStandardBrowserEnv ?
10789
10553
 
10790
- /**
10791
- * Calculate data maxRate
10792
- * @param {Number} [samplesCount= 10]
10793
- * @param {Number} [min= 1000]
10794
- * @returns {Function}
10795
- */
10796
- function speedometer(samplesCount, min) {
10797
- samplesCount = samplesCount || 10;
10798
- const bytes = new Array(samplesCount);
10799
- const timestamps = new Array(samplesCount);
10800
- let head = 0;
10801
- let tail = 0;
10802
- let firstSampleTS;
10554
+ // Standard browser envs support document.cookie
10555
+ {
10556
+ write(name, value, expires, path, domain, secure) {
10557
+ const cookie = [name + '=' + encodeURIComponent(value)];
10803
10558
 
10804
- min = min !== undefined ? min : 1000;
10559
+ utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
10805
10560
 
10806
- return function push(chunkLength) {
10807
- const now = Date.now();
10561
+ utils$1.isString(path) && cookie.push('path=' + path);
10808
10562
 
10809
- const startedAt = timestamps[tail];
10563
+ utils$1.isString(domain) && cookie.push('domain=' + domain);
10810
10564
 
10811
- if (!firstSampleTS) {
10812
- firstSampleTS = now;
10813
- }
10565
+ secure === true && cookie.push('secure');
10814
10566
 
10815
- bytes[head] = chunkLength;
10816
- timestamps[head] = now;
10567
+ document.cookie = cookie.join('; ');
10568
+ },
10817
10569
 
10818
- let i = tail;
10819
- let bytesCount = 0;
10570
+ read(name) {
10571
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
10572
+ return (match ? decodeURIComponent(match[3]) : null);
10573
+ },
10820
10574
 
10821
- while (i !== head) {
10822
- bytesCount += bytes[i++];
10823
- i = i % samplesCount;
10575
+ remove(name) {
10576
+ this.write(name, '', Date.now() - 86400000);
10824
10577
  }
10578
+ }
10825
10579
 
10826
- head = (head + 1) % samplesCount;
10827
-
10828
- if (head === tail) {
10829
- tail = (tail + 1) % samplesCount;
10830
- }
10580
+ :
10831
10581
 
10832
- if (now - firstSampleTS < min) {
10833
- return;
10834
- }
10582
+ // Non-standard browser env (web workers, react-native) lack needed support.
10583
+ {
10584
+ write() {},
10585
+ read() {
10586
+ return null;
10587
+ },
10588
+ remove() {}
10589
+ };
10835
10590
 
10836
- const passed = startedAt && now - startedAt;
10591
+ /**
10592
+ * Determines whether the specified URL is absolute
10593
+ *
10594
+ * @param {string} url The URL to test
10595
+ *
10596
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
10597
+ */
10598
+ function isAbsoluteURL(url) {
10599
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
10600
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
10601
+ // by any combination of letters, digits, plus, period, or hyphen.
10602
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
10603
+ }
10837
10604
 
10838
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
10839
- };
10605
+ /**
10606
+ * Creates a new URL by combining the specified URLs
10607
+ *
10608
+ * @param {string} baseURL The base URL
10609
+ * @param {string} relativeURL The relative URL
10610
+ *
10611
+ * @returns {string} The combined URL
10612
+ */
10613
+ function combineURLs(baseURL, relativeURL) {
10614
+ return relativeURL
10615
+ ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
10616
+ : baseURL;
10840
10617
  }
10841
10618
 
10842
10619
  /**
10843
- * Throttle decorator
10844
- * @param {Function} fn
10845
- * @param {Number} freq
10846
- * @return {Function}
10620
+ * Creates a new URL by combining the baseURL with the requestedURL,
10621
+ * only when the requestedURL is not already an absolute URL.
10622
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
10623
+ *
10624
+ * @param {string} baseURL The base URL
10625
+ * @param {string} requestedURL Absolute or relative URL to combine
10626
+ *
10627
+ * @returns {string} The combined full path
10847
10628
  */
10848
- function throttle(fn, freq) {
10849
- let timestamp = 0;
10850
- let threshold = 1000 / freq;
10851
- let lastArgs;
10852
- let timer;
10629
+ function buildFullPath(baseURL, requestedURL) {
10630
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
10631
+ return combineURLs(baseURL, requestedURL);
10632
+ }
10633
+ return requestedURL;
10634
+ }
10853
10635
 
10854
- const invoke = (args, now = Date.now()) => {
10855
- timestamp = now;
10856
- lastArgs = null;
10857
- if (timer) {
10858
- clearTimeout(timer);
10859
- timer = null;
10860
- }
10861
- fn.apply(null, args);
10862
- };
10636
+ var isURLSameOrigin = platform$1.hasStandardBrowserEnv ?
10863
10637
 
10864
- const throttled = (...args) => {
10865
- const now = Date.now();
10866
- const passed = now - timestamp;
10867
- if ( passed >= threshold) {
10868
- invoke(args, now);
10869
- } else {
10870
- lastArgs = args;
10871
- if (!timer) {
10872
- timer = setTimeout(() => {
10873
- timer = null;
10874
- invoke(lastArgs);
10875
- }, threshold - passed);
10876
- }
10877
- }
10878
- };
10638
+ // Standard browser envs have full support of the APIs needed to test
10639
+ // whether the request URL is of the same origin as current location.
10640
+ (function standardBrowserEnv() {
10641
+ const msie = /(msie|trident)/i.test(navigator.userAgent);
10642
+ const urlParsingNode = document.createElement('a');
10643
+ let originURL;
10879
10644
 
10880
- const flush = () => lastArgs && invoke(lastArgs);
10645
+ /**
10646
+ * Parse a URL to discover its components
10647
+ *
10648
+ * @param {String} url The URL to be parsed
10649
+ * @returns {Object}
10650
+ */
10651
+ function resolveURL(url) {
10652
+ let href = url;
10881
10653
 
10882
- return [throttled, flush];
10883
- }
10884
-
10885
- const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
10886
- let bytesNotified = 0;
10887
- const _speedometer = speedometer(50, 250);
10888
-
10889
- return throttle(e => {
10890
- const loaded = e.loaded;
10891
- const total = e.lengthComputable ? e.total : undefined;
10892
- const progressBytes = loaded - bytesNotified;
10893
- const rate = _speedometer(progressBytes);
10894
- const inRange = loaded <= total;
10895
-
10896
- bytesNotified = loaded;
10897
-
10898
- const data = {
10899
- loaded,
10900
- total,
10901
- progress: total ? (loaded / total) : undefined,
10902
- bytes: progressBytes,
10903
- rate: rate ? rate : undefined,
10904
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
10905
- event: e,
10906
- lengthComputable: total != null,
10907
- [isDownloadStream ? 'download' : 'upload']: true
10908
- };
10909
-
10910
- listener(data);
10911
- }, freq);
10912
- };
10913
-
10914
- const progressEventDecorator = (total, throttled) => {
10915
- const lengthComputable = total != null;
10916
-
10917
- return [(loaded) => throttled[0]({
10918
- lengthComputable,
10919
- total,
10920
- loaded
10921
- }), throttled[1]];
10922
- };
10923
-
10924
- const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
10925
-
10926
- var isURLSameOrigin = platform$1.hasStandardBrowserEnv ?
10927
-
10928
- // Standard browser envs have full support of the APIs needed to test
10929
- // whether the request URL is of the same origin as current location.
10930
- (function standardBrowserEnv() {
10931
- const msie = platform$1.navigator && /(msie|trident)/i.test(platform$1.navigator.userAgent);
10932
- const urlParsingNode = document.createElement('a');
10933
- let originURL;
10934
-
10935
- /**
10936
- * Parse a URL to discover its components
10937
- *
10938
- * @param {String} url The URL to be parsed
10939
- * @returns {Object}
10940
- */
10941
- function resolveURL(url) {
10942
- let href = url;
10943
-
10944
- if (msie) {
10945
- // IE needs attribute set twice to normalize properties
10946
- urlParsingNode.setAttribute('href', href);
10947
- href = urlParsingNode.href;
10948
- }
10654
+ if (msie) {
10655
+ // IE needs attribute set twice to normalize properties
10656
+ urlParsingNode.setAttribute('href', href);
10657
+ href = urlParsingNode.href;
10658
+ }
10949
10659
 
10950
10660
  urlParsingNode.setAttribute('href', href);
10951
10661
 
@@ -10986,267 +10696,137 @@ var isURLSameOrigin = platform$1.hasStandardBrowserEnv ?
10986
10696
  };
10987
10697
  })();
10988
10698
 
10989
- var cookies = platform$1.hasStandardBrowserEnv ?
10990
-
10991
- // Standard browser envs support document.cookie
10992
- {
10993
- write(name, value, expires, path, domain, secure) {
10994
- const cookie = [name + '=' + encodeURIComponent(value)];
10995
-
10996
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
10997
-
10998
- utils$1.isString(path) && cookie.push('path=' + path);
10999
-
11000
- utils$1.isString(domain) && cookie.push('domain=' + domain);
11001
-
11002
- secure === true && cookie.push('secure');
11003
-
11004
- document.cookie = cookie.join('; ');
11005
- },
11006
-
11007
- read(name) {
11008
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
11009
- return (match ? decodeURIComponent(match[3]) : null);
11010
- },
11011
-
11012
- remove(name) {
11013
- this.write(name, '', Date.now() - 86400000);
11014
- }
11015
- }
11016
-
11017
- :
11018
-
11019
- // Non-standard browser env (web workers, react-native) lack needed support.
11020
- {
11021
- write() {},
11022
- read() {
11023
- return null;
11024
- },
11025
- remove() {}
11026
- };
11027
-
11028
- /**
11029
- * Determines whether the specified URL is absolute
11030
- *
11031
- * @param {string} url The URL to test
11032
- *
11033
- * @returns {boolean} True if the specified URL is absolute, otherwise false
11034
- */
11035
- function isAbsoluteURL(url) {
11036
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
11037
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
11038
- // by any combination of letters, digits, plus, period, or hyphen.
11039
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
10699
+ function parseProtocol(url) {
10700
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
10701
+ return match && match[1] || '';
11040
10702
  }
11041
10703
 
11042
10704
  /**
11043
- * Creates a new URL by combining the specified URLs
11044
- *
11045
- * @param {string} baseURL The base URL
11046
- * @param {string} relativeURL The relative URL
11047
- *
11048
- * @returns {string} The combined URL
10705
+ * Calculate data maxRate
10706
+ * @param {Number} [samplesCount= 10]
10707
+ * @param {Number} [min= 1000]
10708
+ * @returns {Function}
11049
10709
  */
11050
- function combineURLs(baseURL, relativeURL) {
11051
- return relativeURL
11052
- ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
11053
- : baseURL;
11054
- }
10710
+ function speedometer(samplesCount, min) {
10711
+ samplesCount = samplesCount || 10;
10712
+ const bytes = new Array(samplesCount);
10713
+ const timestamps = new Array(samplesCount);
10714
+ let head = 0;
10715
+ let tail = 0;
10716
+ let firstSampleTS;
11055
10717
 
11056
- /**
11057
- * Creates a new URL by combining the baseURL with the requestedURL,
11058
- * only when the requestedURL is not already an absolute URL.
11059
- * If the requestURL is absolute, this function returns the requestedURL untouched.
11060
- *
11061
- * @param {string} baseURL The base URL
11062
- * @param {string} requestedURL Absolute or relative URL to combine
11063
- *
11064
- * @returns {string} The combined full path
11065
- */
11066
- function buildFullPath(baseURL, requestedURL) {
11067
- if (baseURL && !isAbsoluteURL(requestedURL)) {
11068
- return combineURLs(baseURL, requestedURL);
11069
- }
11070
- return requestedURL;
11071
- }
10718
+ min = min !== undefined ? min : 1000;
11072
10719
 
11073
- const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
10720
+ return function push(chunkLength) {
10721
+ const now = Date.now();
11074
10722
 
11075
- /**
11076
- * Config-specific merge-function which creates a new config-object
11077
- * by merging two configuration objects together.
11078
- *
11079
- * @param {Object} config1
11080
- * @param {Object} config2
11081
- *
11082
- * @returns {Object} New object resulting from merging config2 to config1
11083
- */
11084
- function mergeConfig(config1, config2) {
11085
- // eslint-disable-next-line no-param-reassign
11086
- config2 = config2 || {};
11087
- const config = {};
10723
+ const startedAt = timestamps[tail];
11088
10724
 
11089
- function getMergedValue(target, source, caseless) {
11090
- if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
11091
- return utils$1.merge.call({caseless}, target, source);
11092
- } else if (utils$1.isPlainObject(source)) {
11093
- return utils$1.merge({}, source);
11094
- } else if (utils$1.isArray(source)) {
11095
- return source.slice();
10725
+ if (!firstSampleTS) {
10726
+ firstSampleTS = now;
11096
10727
  }
11097
- return source;
11098
- }
11099
10728
 
11100
- // eslint-disable-next-line consistent-return
11101
- function mergeDeepProperties(a, b, caseless) {
11102
- if (!utils$1.isUndefined(b)) {
11103
- return getMergedValue(a, b, caseless);
11104
- } else if (!utils$1.isUndefined(a)) {
11105
- return getMergedValue(undefined, a, caseless);
11106
- }
11107
- }
10729
+ bytes[head] = chunkLength;
10730
+ timestamps[head] = now;
11108
10731
 
11109
- // eslint-disable-next-line consistent-return
11110
- function valueFromConfig2(a, b) {
11111
- if (!utils$1.isUndefined(b)) {
11112
- return getMergedValue(undefined, b);
11113
- }
11114
- }
10732
+ let i = tail;
10733
+ let bytesCount = 0;
11115
10734
 
11116
- // eslint-disable-next-line consistent-return
11117
- function defaultToConfig2(a, b) {
11118
- if (!utils$1.isUndefined(b)) {
11119
- return getMergedValue(undefined, b);
11120
- } else if (!utils$1.isUndefined(a)) {
11121
- return getMergedValue(undefined, a);
10735
+ while (i !== head) {
10736
+ bytesCount += bytes[i++];
10737
+ i = i % samplesCount;
11122
10738
  }
11123
- }
11124
10739
 
11125
- // eslint-disable-next-line consistent-return
11126
- function mergeDirectKeys(a, b, prop) {
11127
- if (prop in config2) {
11128
- return getMergedValue(a, b);
11129
- } else if (prop in config1) {
11130
- return getMergedValue(undefined, a);
10740
+ head = (head + 1) % samplesCount;
10741
+
10742
+ if (head === tail) {
10743
+ tail = (tail + 1) % samplesCount;
11131
10744
  }
11132
- }
11133
10745
 
11134
- const mergeMap = {
11135
- url: valueFromConfig2,
11136
- method: valueFromConfig2,
11137
- data: valueFromConfig2,
11138
- baseURL: defaultToConfig2,
11139
- transformRequest: defaultToConfig2,
11140
- transformResponse: defaultToConfig2,
11141
- paramsSerializer: defaultToConfig2,
11142
- timeout: defaultToConfig2,
11143
- timeoutMessage: defaultToConfig2,
11144
- withCredentials: defaultToConfig2,
11145
- withXSRFToken: defaultToConfig2,
11146
- adapter: defaultToConfig2,
11147
- responseType: defaultToConfig2,
11148
- xsrfCookieName: defaultToConfig2,
11149
- xsrfHeaderName: defaultToConfig2,
11150
- onUploadProgress: defaultToConfig2,
11151
- onDownloadProgress: defaultToConfig2,
11152
- decompress: defaultToConfig2,
11153
- maxContentLength: defaultToConfig2,
11154
- maxBodyLength: defaultToConfig2,
11155
- beforeRedirect: defaultToConfig2,
11156
- transport: defaultToConfig2,
11157
- httpAgent: defaultToConfig2,
11158
- httpsAgent: defaultToConfig2,
11159
- cancelToken: defaultToConfig2,
11160
- socketPath: defaultToConfig2,
11161
- responseEncoding: defaultToConfig2,
11162
- validateStatus: mergeDirectKeys,
11163
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
11164
- };
10746
+ if (now - firstSampleTS < min) {
10747
+ return;
10748
+ }
11165
10749
 
11166
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
11167
- const merge = mergeMap[prop] || mergeDeepProperties;
11168
- const configValue = merge(config1[prop], config2[prop], prop);
11169
- (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
11170
- });
10750
+ const passed = startedAt && now - startedAt;
11171
10751
 
11172
- return config;
10752
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
10753
+ };
11173
10754
  }
11174
10755
 
11175
- var resolveConfig = (config) => {
11176
- const newConfig = mergeConfig({}, config);
11177
-
11178
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
11179
-
11180
- newConfig.headers = headers = AxiosHeaders.from(headers);
11181
-
11182
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
11183
-
11184
- // HTTP basic authentication
11185
- if (auth) {
11186
- headers.set('Authorization', 'Basic ' +
11187
- btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
11188
- );
11189
- }
11190
-
11191
- let contentType;
11192
-
11193
- if (utils$1.isFormData(data)) {
11194
- if (platform$1.hasStandardBrowserEnv || platform$1.hasStandardBrowserWebWorkerEnv) {
11195
- headers.setContentType(undefined); // Let the browser set it
11196
- } else if ((contentType = headers.getContentType()) !== false) {
11197
- // fix semicolon duplication issue for ReactNative FormData implementation
11198
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
11199
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
11200
- }
11201
- }
10756
+ function progressEventReducer(listener, isDownloadStream) {
10757
+ let bytesNotified = 0;
10758
+ const _speedometer = speedometer(50, 250);
11202
10759
 
11203
- // Add xsrf header
11204
- // This is only done if running in a standard browser environment.
11205
- // Specifically not if we're in a web worker, or react-native.
10760
+ return e => {
10761
+ const loaded = e.loaded;
10762
+ const total = e.lengthComputable ? e.total : undefined;
10763
+ const progressBytes = loaded - bytesNotified;
10764
+ const rate = _speedometer(progressBytes);
10765
+ const inRange = loaded <= total;
11206
10766
 
11207
- if (platform$1.hasStandardBrowserEnv) {
11208
- withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
10767
+ bytesNotified = loaded;
11209
10768
 
11210
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
11211
- // Add xsrf header
11212
- const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
10769
+ const data = {
10770
+ loaded,
10771
+ total,
10772
+ progress: total ? (loaded / total) : undefined,
10773
+ bytes: progressBytes,
10774
+ rate: rate ? rate : undefined,
10775
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
10776
+ event: e
10777
+ };
11213
10778
 
11214
- if (xsrfValue) {
11215
- headers.set(xsrfHeaderName, xsrfValue);
11216
- }
11217
- }
11218
- }
10779
+ data[isDownloadStream ? 'download' : 'upload'] = true;
11219
10780
 
11220
- return newConfig;
11221
- };
10781
+ listener(data);
10782
+ };
10783
+ }
11222
10784
 
11223
10785
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
11224
10786
 
11225
10787
  var xhrAdapter = isXHRAdapterSupported && function (config) {
11226
10788
  return new Promise(function dispatchXhrRequest(resolve, reject) {
11227
- const _config = resolveConfig(config);
11228
- let requestData = _config.data;
11229
- const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
11230
- let {responseType, onUploadProgress, onDownloadProgress} = _config;
10789
+ let requestData = config.data;
10790
+ const requestHeaders = AxiosHeaders.from(config.headers).normalize();
10791
+ let {responseType, withXSRFToken} = config;
11231
10792
  let onCanceled;
11232
- let uploadThrottled, downloadThrottled;
11233
- let flushUpload, flushDownload;
11234
-
11235
10793
  function done() {
11236
- flushUpload && flushUpload(); // flush events
11237
- flushDownload && flushDownload(); // flush events
10794
+ if (config.cancelToken) {
10795
+ config.cancelToken.unsubscribe(onCanceled);
10796
+ }
10797
+
10798
+ if (config.signal) {
10799
+ config.signal.removeEventListener('abort', onCanceled);
10800
+ }
10801
+ }
11238
10802
 
11239
- _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
10803
+ let contentType;
11240
10804
 
11241
- _config.signal && _config.signal.removeEventListener('abort', onCanceled);
10805
+ if (utils$1.isFormData(requestData)) {
10806
+ if (platform$1.hasStandardBrowserEnv || platform$1.hasStandardBrowserWebWorkerEnv) {
10807
+ requestHeaders.setContentType(false); // Let the browser set it
10808
+ } else if ((contentType = requestHeaders.getContentType()) !== false) {
10809
+ // fix semicolon duplication issue for ReactNative FormData implementation
10810
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
10811
+ requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
10812
+ }
11242
10813
  }
11243
10814
 
11244
10815
  let request = new XMLHttpRequest();
11245
10816
 
11246
- request.open(_config.method.toUpperCase(), _config.url, true);
10817
+ // HTTP basic authentication
10818
+ if (config.auth) {
10819
+ const username = config.auth.username || '';
10820
+ const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
10821
+ requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
10822
+ }
10823
+
10824
+ const fullPath = buildFullPath(config.baseURL, config.url);
10825
+
10826
+ request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
11247
10827
 
11248
10828
  // Set the request timeout in MS
11249
- request.timeout = _config.timeout;
10829
+ request.timeout = config.timeout;
11250
10830
 
11251
10831
  function onloadend() {
11252
10832
  if (!request) {
@@ -11326,10 +10906,10 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
11326
10906
 
11327
10907
  // Handle timeout
11328
10908
  request.ontimeout = function handleTimeout() {
11329
- let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
11330
- const transitional = _config.transitional || transitionalDefaults;
11331
- if (_config.timeoutErrorMessage) {
11332
- timeoutErrorMessage = _config.timeoutErrorMessage;
10909
+ let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
10910
+ const transitional = config.transitional || transitionalDefaults;
10911
+ if (config.timeoutErrorMessage) {
10912
+ timeoutErrorMessage = config.timeoutErrorMessage;
11333
10913
  }
11334
10914
  reject(new AxiosError(
11335
10915
  timeoutErrorMessage,
@@ -11341,6 +10921,22 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
11341
10921
  request = null;
11342
10922
  };
11343
10923
 
10924
+ // Add xsrf header
10925
+ // This is only done if running in a standard browser environment.
10926
+ // Specifically not if we're in a web worker, or react-native.
10927
+ if(platform$1.hasStandardBrowserEnv) {
10928
+ withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
10929
+
10930
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
10931
+ // Add xsrf header
10932
+ const xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
10933
+
10934
+ if (xsrfValue) {
10935
+ requestHeaders.set(config.xsrfHeaderName, xsrfValue);
10936
+ }
10937
+ }
10938
+ }
10939
+
11344
10940
  // Remove Content-Type if data is undefined
11345
10941
  requestData === undefined && requestHeaders.setContentType(null);
11346
10942
 
@@ -11352,31 +10948,26 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
11352
10948
  }
11353
10949
 
11354
10950
  // Add withCredentials to request if needed
11355
- if (!utils$1.isUndefined(_config.withCredentials)) {
11356
- request.withCredentials = !!_config.withCredentials;
10951
+ if (!utils$1.isUndefined(config.withCredentials)) {
10952
+ request.withCredentials = !!config.withCredentials;
11357
10953
  }
11358
10954
 
11359
10955
  // Add responseType to request if needed
11360
10956
  if (responseType && responseType !== 'json') {
11361
- request.responseType = _config.responseType;
10957
+ request.responseType = config.responseType;
11362
10958
  }
11363
10959
 
11364
10960
  // Handle progress if needed
11365
- if (onDownloadProgress) {
11366
- ([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
11367
- request.addEventListener('progress', downloadThrottled);
10961
+ if (typeof config.onDownloadProgress === 'function') {
10962
+ request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
11368
10963
  }
11369
10964
 
11370
10965
  // Not all browsers support upload events
11371
- if (onUploadProgress && request.upload) {
11372
- ([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
11373
-
11374
- request.upload.addEventListener('progress', uploadThrottled);
11375
-
11376
- request.upload.addEventListener('loadend', flushUpload);
10966
+ if (typeof config.onUploadProgress === 'function' && request.upload) {
10967
+ request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
11377
10968
  }
11378
10969
 
11379
- if (_config.cancelToken || _config.signal) {
10970
+ if (config.cancelToken || config.signal) {
11380
10971
  // Handle cancellation
11381
10972
  // eslint-disable-next-line func-names
11382
10973
  onCanceled = cancel => {
@@ -11388,13 +10979,13 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
11388
10979
  request = null;
11389
10980
  };
11390
10981
 
11391
- _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
11392
- if (_config.signal) {
11393
- _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
10982
+ config.cancelToken && config.cancelToken.subscribe(onCanceled);
10983
+ if (config.signal) {
10984
+ config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
11394
10985
  }
11395
10986
  }
11396
10987
 
11397
- const protocol = parseProtocol(_config.url);
10988
+ const protocol = parseProtocol(fullPath);
11398
10989
 
11399
10990
  if (protocol && platform$1.protocols.indexOf(protocol) === -1) {
11400
10991
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
@@ -11407,358 +10998,9 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
11407
10998
  });
11408
10999
  };
11409
11000
 
11410
- const composeSignals = (signals, timeout) => {
11411
- const {length} = (signals = signals ? signals.filter(Boolean) : []);
11412
-
11413
- if (timeout || length) {
11414
- let controller = new AbortController();
11415
-
11416
- let aborted;
11417
-
11418
- const onabort = function (reason) {
11419
- if (!aborted) {
11420
- aborted = true;
11421
- unsubscribe();
11422
- const err = reason instanceof Error ? reason : this.reason;
11423
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
11424
- }
11425
- };
11426
-
11427
- let timer = timeout && setTimeout(() => {
11428
- timer = null;
11429
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
11430
- }, timeout);
11431
-
11432
- const unsubscribe = () => {
11433
- if (signals) {
11434
- timer && clearTimeout(timer);
11435
- timer = null;
11436
- signals.forEach(signal => {
11437
- signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
11438
- });
11439
- signals = null;
11440
- }
11441
- };
11442
-
11443
- signals.forEach((signal) => signal.addEventListener('abort', onabort));
11444
-
11445
- const {signal} = controller;
11446
-
11447
- signal.unsubscribe = () => utils$1.asap(unsubscribe);
11448
-
11449
- return signal;
11450
- }
11451
- };
11452
-
11453
- const streamChunk = function* (chunk, chunkSize) {
11454
- let len = chunk.byteLength;
11455
-
11456
- if (!chunkSize || len < chunkSize) {
11457
- yield chunk;
11458
- return;
11459
- }
11460
-
11461
- let pos = 0;
11462
- let end;
11463
-
11464
- while (pos < len) {
11465
- end = pos + chunkSize;
11466
- yield chunk.slice(pos, end);
11467
- pos = end;
11468
- }
11469
- };
11470
-
11471
- const readBytes = async function* (iterable, chunkSize) {
11472
- for await (const chunk of readStream(iterable)) {
11473
- yield* streamChunk(chunk, chunkSize);
11474
- }
11475
- };
11476
-
11477
- const readStream = async function* (stream) {
11478
- if (stream[Symbol.asyncIterator]) {
11479
- yield* stream;
11480
- return;
11481
- }
11482
-
11483
- const reader = stream.getReader();
11484
- try {
11485
- for (;;) {
11486
- const {done, value} = await reader.read();
11487
- if (done) {
11488
- break;
11489
- }
11490
- yield value;
11491
- }
11492
- } finally {
11493
- await reader.cancel();
11494
- }
11495
- };
11496
-
11497
- const trackStream = (stream, chunkSize, onProgress, onFinish) => {
11498
- const iterator = readBytes(stream, chunkSize);
11499
-
11500
- let bytes = 0;
11501
- let done;
11502
- let _onFinish = (e) => {
11503
- if (!done) {
11504
- done = true;
11505
- onFinish && onFinish(e);
11506
- }
11507
- };
11508
-
11509
- return new ReadableStream({
11510
- async pull(controller) {
11511
- try {
11512
- const {done, value} = await iterator.next();
11513
-
11514
- if (done) {
11515
- _onFinish();
11516
- controller.close();
11517
- return;
11518
- }
11519
-
11520
- let len = value.byteLength;
11521
- if (onProgress) {
11522
- let loadedBytes = bytes += len;
11523
- onProgress(loadedBytes);
11524
- }
11525
- controller.enqueue(new Uint8Array(value));
11526
- } catch (err) {
11527
- _onFinish(err);
11528
- throw err;
11529
- }
11530
- },
11531
- cancel(reason) {
11532
- _onFinish(reason);
11533
- return iterator.return();
11534
- }
11535
- }, {
11536
- highWaterMark: 2
11537
- })
11538
- };
11539
-
11540
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
11541
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
11542
-
11543
- // used only inside the fetch adapter
11544
- const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
11545
- ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
11546
- async (str) => new Uint8Array(await new Response(str).arrayBuffer())
11547
- );
11548
-
11549
- const test = (fn, ...args) => {
11550
- try {
11551
- return !!fn(...args);
11552
- } catch (e) {
11553
- return false
11554
- }
11555
- };
11556
-
11557
- const supportsRequestStream = isReadableStreamSupported && test(() => {
11558
- let duplexAccessed = false;
11559
-
11560
- const hasContentType = new Request(platform$1.origin, {
11561
- body: new ReadableStream(),
11562
- method: 'POST',
11563
- get duplex() {
11564
- duplexAccessed = true;
11565
- return 'half';
11566
- },
11567
- }).headers.has('Content-Type');
11568
-
11569
- return duplexAccessed && !hasContentType;
11570
- });
11571
-
11572
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
11573
-
11574
- const supportsResponseStream = isReadableStreamSupported &&
11575
- test(() => utils$1.isReadableStream(new Response('').body));
11576
-
11577
-
11578
- const resolvers = {
11579
- stream: supportsResponseStream && ((res) => res.body)
11580
- };
11581
-
11582
- isFetchSupported && (((res) => {
11583
- ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
11584
- !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
11585
- (_, config) => {
11586
- throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
11587
- });
11588
- });
11589
- })(new Response));
11590
-
11591
- const getBodyLength = async (body) => {
11592
- if (body == null) {
11593
- return 0;
11594
- }
11595
-
11596
- if(utils$1.isBlob(body)) {
11597
- return body.size;
11598
- }
11599
-
11600
- if(utils$1.isSpecCompliantForm(body)) {
11601
- const _request = new Request(platform$1.origin, {
11602
- method: 'POST',
11603
- body,
11604
- });
11605
- return (await _request.arrayBuffer()).byteLength;
11606
- }
11607
-
11608
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
11609
- return body.byteLength;
11610
- }
11611
-
11612
- if(utils$1.isURLSearchParams(body)) {
11613
- body = body + '';
11614
- }
11615
-
11616
- if(utils$1.isString(body)) {
11617
- return (await encodeText(body)).byteLength;
11618
- }
11619
- };
11620
-
11621
- const resolveBodyLength = async (headers, body) => {
11622
- const length = utils$1.toFiniteNumber(headers.getContentLength());
11623
-
11624
- return length == null ? getBodyLength(body) : length;
11625
- };
11626
-
11627
- var fetchAdapter = isFetchSupported && (async (config) => {
11628
- let {
11629
- url,
11630
- method,
11631
- data,
11632
- signal,
11633
- cancelToken,
11634
- timeout,
11635
- onDownloadProgress,
11636
- onUploadProgress,
11637
- responseType,
11638
- headers,
11639
- withCredentials = 'same-origin',
11640
- fetchOptions
11641
- } = resolveConfig(config);
11642
-
11643
- responseType = responseType ? (responseType + '').toLowerCase() : 'text';
11644
-
11645
- let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
11646
-
11647
- let request;
11648
-
11649
- const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
11650
- composedSignal.unsubscribe();
11651
- });
11652
-
11653
- let requestContentLength;
11654
-
11655
- try {
11656
- if (
11657
- onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
11658
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
11659
- ) {
11660
- let _request = new Request(url, {
11661
- method: 'POST',
11662
- body: data,
11663
- duplex: "half"
11664
- });
11665
-
11666
- let contentTypeHeader;
11667
-
11668
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
11669
- headers.setContentType(contentTypeHeader);
11670
- }
11671
-
11672
- if (_request.body) {
11673
- const [onProgress, flush] = progressEventDecorator(
11674
- requestContentLength,
11675
- progressEventReducer(asyncDecorator(onUploadProgress))
11676
- );
11677
-
11678
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
11679
- }
11680
- }
11681
-
11682
- if (!utils$1.isString(withCredentials)) {
11683
- withCredentials = withCredentials ? 'include' : 'omit';
11684
- }
11685
-
11686
- // Cloudflare Workers throws when credentials are defined
11687
- // see https://github.com/cloudflare/workerd/issues/902
11688
- const isCredentialsSupported = "credentials" in Request.prototype;
11689
- request = new Request(url, {
11690
- ...fetchOptions,
11691
- signal: composedSignal,
11692
- method: method.toUpperCase(),
11693
- headers: headers.normalize().toJSON(),
11694
- body: data,
11695
- duplex: "half",
11696
- credentials: isCredentialsSupported ? withCredentials : undefined
11697
- });
11698
-
11699
- let response = await fetch(request);
11700
-
11701
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
11702
-
11703
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
11704
- const options = {};
11705
-
11706
- ['status', 'statusText', 'headers'].forEach(prop => {
11707
- options[prop] = response[prop];
11708
- });
11709
-
11710
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
11711
-
11712
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
11713
- responseContentLength,
11714
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
11715
- ) || [];
11716
-
11717
- response = new Response(
11718
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
11719
- flush && flush();
11720
- unsubscribe && unsubscribe();
11721
- }),
11722
- options
11723
- );
11724
- }
11725
-
11726
- responseType = responseType || 'text';
11727
-
11728
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
11729
-
11730
- !isStreamResponse && unsubscribe && unsubscribe();
11731
-
11732
- return await new Promise((resolve, reject) => {
11733
- settle(resolve, reject, {
11734
- data: responseData,
11735
- headers: AxiosHeaders.from(response.headers),
11736
- status: response.status,
11737
- statusText: response.statusText,
11738
- config,
11739
- request
11740
- });
11741
- })
11742
- } catch (err) {
11743
- unsubscribe && unsubscribe();
11744
-
11745
- if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
11746
- throw Object.assign(
11747
- new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
11748
- {
11749
- cause: err.cause || err
11750
- }
11751
- )
11752
- }
11753
-
11754
- throw AxiosError.from(err, err && err.code, config, request);
11755
- }
11756
- });
11757
-
11758
11001
  const knownAdapters = {
11759
11002
  http: httpAdapter,
11760
- xhr: xhrAdapter,
11761
- fetch: fetchAdapter
11003
+ xhr: xhrAdapter
11762
11004
  };
11763
11005
 
11764
11006
  utils$1.forEach(knownAdapters, (fn, value) => {
@@ -11902,7 +11144,109 @@ function dispatchRequest(config) {
11902
11144
  });
11903
11145
  }
11904
11146
 
11905
- const VERSION = "1.7.7";
11147
+ const headersToObject = (thing) => thing instanceof AxiosHeaders ? thing.toJSON() : thing;
11148
+
11149
+ /**
11150
+ * Config-specific merge-function which creates a new config-object
11151
+ * by merging two configuration objects together.
11152
+ *
11153
+ * @param {Object} config1
11154
+ * @param {Object} config2
11155
+ *
11156
+ * @returns {Object} New object resulting from merging config2 to config1
11157
+ */
11158
+ function mergeConfig(config1, config2) {
11159
+ // eslint-disable-next-line no-param-reassign
11160
+ config2 = config2 || {};
11161
+ const config = {};
11162
+
11163
+ function getMergedValue(target, source, caseless) {
11164
+ if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
11165
+ return utils$1.merge.call({caseless}, target, source);
11166
+ } else if (utils$1.isPlainObject(source)) {
11167
+ return utils$1.merge({}, source);
11168
+ } else if (utils$1.isArray(source)) {
11169
+ return source.slice();
11170
+ }
11171
+ return source;
11172
+ }
11173
+
11174
+ // eslint-disable-next-line consistent-return
11175
+ function mergeDeepProperties(a, b, caseless) {
11176
+ if (!utils$1.isUndefined(b)) {
11177
+ return getMergedValue(a, b, caseless);
11178
+ } else if (!utils$1.isUndefined(a)) {
11179
+ return getMergedValue(undefined, a, caseless);
11180
+ }
11181
+ }
11182
+
11183
+ // eslint-disable-next-line consistent-return
11184
+ function valueFromConfig2(a, b) {
11185
+ if (!utils$1.isUndefined(b)) {
11186
+ return getMergedValue(undefined, b);
11187
+ }
11188
+ }
11189
+
11190
+ // eslint-disable-next-line consistent-return
11191
+ function defaultToConfig2(a, b) {
11192
+ if (!utils$1.isUndefined(b)) {
11193
+ return getMergedValue(undefined, b);
11194
+ } else if (!utils$1.isUndefined(a)) {
11195
+ return getMergedValue(undefined, a);
11196
+ }
11197
+ }
11198
+
11199
+ // eslint-disable-next-line consistent-return
11200
+ function mergeDirectKeys(a, b, prop) {
11201
+ if (prop in config2) {
11202
+ return getMergedValue(a, b);
11203
+ } else if (prop in config1) {
11204
+ return getMergedValue(undefined, a);
11205
+ }
11206
+ }
11207
+
11208
+ const mergeMap = {
11209
+ url: valueFromConfig2,
11210
+ method: valueFromConfig2,
11211
+ data: valueFromConfig2,
11212
+ baseURL: defaultToConfig2,
11213
+ transformRequest: defaultToConfig2,
11214
+ transformResponse: defaultToConfig2,
11215
+ paramsSerializer: defaultToConfig2,
11216
+ timeout: defaultToConfig2,
11217
+ timeoutMessage: defaultToConfig2,
11218
+ withCredentials: defaultToConfig2,
11219
+ withXSRFToken: defaultToConfig2,
11220
+ adapter: defaultToConfig2,
11221
+ responseType: defaultToConfig2,
11222
+ xsrfCookieName: defaultToConfig2,
11223
+ xsrfHeaderName: defaultToConfig2,
11224
+ onUploadProgress: defaultToConfig2,
11225
+ onDownloadProgress: defaultToConfig2,
11226
+ decompress: defaultToConfig2,
11227
+ maxContentLength: defaultToConfig2,
11228
+ maxBodyLength: defaultToConfig2,
11229
+ beforeRedirect: defaultToConfig2,
11230
+ transport: defaultToConfig2,
11231
+ httpAgent: defaultToConfig2,
11232
+ httpsAgent: defaultToConfig2,
11233
+ cancelToken: defaultToConfig2,
11234
+ socketPath: defaultToConfig2,
11235
+ responseEncoding: defaultToConfig2,
11236
+ validateStatus: mergeDirectKeys,
11237
+ headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
11238
+ };
11239
+
11240
+ utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
11241
+ const merge = mergeMap[prop] || mergeDeepProperties;
11242
+ const configValue = merge(config1[prop], config2[prop], prop);
11243
+ (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
11244
+ });
11245
+
11246
+ return config;
11247
+ }
11248
+
11249
+ const VERSION = "1.6.7";
11906
11250
 
11907
11251
  const validators = {};
11908
11252
 
@@ -12028,15 +11372,12 @@ class Axios {
12028
11372
 
12029
11373
  // slice off the Error: ... line
12030
11374
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
12031
- try {
12032
- if (!err.stack) {
12033
- err.stack = stack;
12034
- // match without the 2 top stack lines
12035
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
12036
- err.stack += '\n' + stack;
12037
- }
12038
- } catch (e) {
12039
- // ignore the case where "stack" is an un-writable property
11375
+
11376
+ if (!err.stack) {
11377
+ err.stack = stack;
11378
+ // match without the 2 top stack lines
11379
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
11380
+ err.stack += '\n' + stack;
12040
11381
  }
12041
11382
  }
12042
11383
 
@@ -12307,20 +11648,6 @@ class CancelToken {
12307
11648
  }
12308
11649
  }
12309
11650
 
12310
- toAbortSignal() {
12311
- const controller = new AbortController();
12312
-
12313
- const abort = (err) => {
12314
- controller.abort(err);
12315
- };
12316
-
12317
- this.subscribe(abort);
12318
-
12319
- controller.signal.unsubscribe = () => this.unsubscribe(abort);
12320
-
12321
- return controller.signal;
12322
- }
12323
-
12324
11651
  /**
12325
11652
  * Returns an object that contains a new `CancelToken` and a function that, when called,
12326
11653
  * cancels the `CancelToken`.