@depay/widgets 6.15.0 → 6.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48843,6 +48843,10 @@ const submitSimpleTransfer = ({ transaction, wallet })=>{
48843
48843
  function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
48844
48844
  let connectedInstance;
48845
48845
 
48846
+ const getConnectedInstance = ()=>{
48847
+ return connectedInstance
48848
+ };
48849
+
48846
48850
  class WalletConnectWallet {
48847
48851
 
48848
48852
  static __initStatic() {this.info = {
@@ -48915,6 +48919,10 @@ class WalletConnectWallet {
48915
48919
 
48916
48920
  async connect(options) {
48917
48921
  try {
48922
+ if(this.connector == undefined){
48923
+ this.connector = this.newWalletConnectInstance();
48924
+ }
48925
+
48918
48926
  if(this.connector.connected) {
48919
48927
  await this.connector.killSession();
48920
48928
  connectedInstance = undefined;
@@ -48931,7 +48939,8 @@ class WalletConnectWallet {
48931
48939
  this.connectedChainId = chainId;
48932
48940
 
48933
48941
  return accounts
48934
- } catch (e) {
48942
+ } catch (error) {
48943
+ console.log('WALLETCONNECT ERROR', error);
48935
48944
  return []
48936
48945
  }
48937
48946
  }
@@ -49025,7 +49034,7 @@ const wallets = {
49025
49034
  const instances = {};
49026
49035
 
49027
49036
  const getWalletClass = function(){
49028
- if(connectedInstance) {
49037
+ if(getConnectedInstance()) {
49029
49038
  return wallets.WalletConnect
49030
49039
  } else if (typeof window.ethereum === 'object' && window.ethereum.isMetaMask) {
49031
49040
  return wallets.MetaMask
@@ -49040,8 +49049,8 @@ const getWallet = function () {
49040
49049
  const walletClass = getWalletClass();
49041
49050
  const existingInstance = instances[walletClass];
49042
49051
 
49043
- if(connectedInstance) {
49044
- return connectedInstance
49052
+ if(getConnectedInstance()) {
49053
+ return getConnectedInstance()
49045
49054
  } else if(existingInstance) {
49046
49055
  return existingInstance
49047
49056
  } else if(walletClass) {
@@ -55315,17 +55324,21 @@ class Token {
55315
55324
  if (this.address == CONSTANTS$2[this.blockchain].NATIVE) {
55316
55325
  return CONSTANTS$2[this.blockchain].DECIMALS
55317
55326
  }
55318
- return await request(
55319
- {
55320
- blockchain: this.blockchain,
55321
- address: this.address,
55322
- method: 'decimals',
55323
- },
55324
- {
55325
- api: Token[this.blockchain].DEFAULT,
55326
- cache: 86400000, // 1 day
55327
- },
55328
- )
55327
+ let decimals = 0;
55328
+ try {
55329
+ decimals = await request(
55330
+ {
55331
+ blockchain: this.blockchain,
55332
+ address: this.address,
55333
+ method: 'decimals',
55334
+ },
55335
+ {
55336
+ api: Token[this.blockchain].DEFAULT,
55337
+ cache: 86400000, // 1 day
55338
+ },
55339
+ );
55340
+ } catch (e) {}
55341
+ return decimals
55329
55342
  }
55330
55343
 
55331
55344
  async symbol() {
@@ -62471,7 +62484,7 @@ var PaymentProvider = (function (props) {
62471
62484
  var _useContext9 = react.useContext(PaymentTrackingContext),
62472
62485
  release = _useContext9.release,
62473
62486
  tracking = _useContext9.tracking,
62474
- initializeTracking = _useContext9.initializeTracking;
62487
+ initializePaymentTracking = _useContext9.initializeTracking;
62475
62488
 
62476
62489
  var _useContext10 = react.useContext(TransactionTrackingContext),
62477
62490
  foundTransaction = _useContext10.foundTransaction,
@@ -62551,10 +62564,7 @@ var PaymentProvider = (function (props) {
62551
62564
  confirmed: paymentConfirmed,
62552
62565
  failed: paymentFailed
62553
62566
  })).then(function (sentTransaction) {
62554
- if (tracking) {
62555
- initializeTracking(sentTransaction, currentBlock, payment.route);
62556
- }
62557
-
62567
+ initializePaymentTracking(sentTransaction, currentBlock, payment.route);
62558
62568
  setTransaction(sentTransaction);
62559
62569
  })["catch"](function (error) {
62560
62570
  console.log('error', error);
@@ -67687,10 +67697,10 @@ class PaymentRoute {
67687
67697
  this.fromAddress = fromAddress;
67688
67698
  this.fromToken = fromToken;
67689
67699
  this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
67690
- this.fromDecimals = _optionalChain([fromDecimals, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67700
+ this.fromDecimals = fromDecimals;
67691
67701
  this.fromBalance = 0;
67692
67702
  this.toToken = toToken;
67693
- this.toAmount = _optionalChain([toAmount, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]);
67703
+ this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67694
67704
  this.toDecimals = toDecimals;
67695
67705
  this.toAddress = toAddress;
67696
67706
  this.toContract = toContract;
@@ -67754,12 +67764,14 @@ function convertToRoutes({ tokens, accept }) {
67754
67764
  if(configuration.token && configuration.amount) {
67755
67765
  let blockchain = configuration.blockchain;
67756
67766
  let toToken = new Token({ blockchain, address: configuration.token });
67767
+ let fromDecimals = await fromToken.decimals();
67757
67768
  let toDecimals = await toToken.decimals();
67758
67769
  let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
67759
67770
 
67760
67771
  return new PaymentRoute({
67761
67772
  blockchain,
67762
67773
  fromToken,
67774
+ fromDecimals,
67763
67775
  toToken,
67764
67776
  toAmount,
67765
67777
  toDecimals,
@@ -67804,7 +67816,7 @@ async function route({ accept, whitelist, blacklist, apiKey, event, fee }) {
67804
67816
  .then(addApproval)
67805
67817
  .then(sortPaymentRoutes)
67806
67818
  .then((routes)=>addTransactions({ routes, event, fee }))
67807
- .then(addFromAmount)
67819
+ .then(addRouteAmounts)
67808
67820
  .then(filterDuplicateFromTokens);
67809
67821
 
67810
67822
  return paymentRoutes
@@ -67937,16 +67949,19 @@ let addDirectTransferStatus = (routes) => {
67937
67949
  })
67938
67950
  };
67939
67951
 
67940
- let addFromAmount = (routes)=> {
67952
+ let addRouteAmounts = (routes)=> {
67941
67953
  return routes.map((route)=>{
67942
67954
  if(route.directTransfer && !route.fee) {
67943
67955
  if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
67944
67956
  route.fromAmount = route.transaction.value;
67957
+ route.toAmount = route.transaction.value;
67945
67958
  } else {
67946
67959
  route.fromAmount = route.transaction.params[1];
67960
+ route.toAmount = route.transaction.params[1];
67947
67961
  }
67948
67962
  } else {
67949
67963
  route.fromAmount = route.transaction.params.amounts[0];
67964
+ route.toAmount = route.transaction.params.amounts[1];
67950
67965
  }
67951
67966
  return route
67952
67967
  })
@@ -68269,7 +68284,7 @@ var PaymentValueProvider = (function (props) {
68269
68284
  var paymentAmountInBN = BigNumber$4.from(payment.route.fromAmount);
68270
68285
  var divPercent = 100 - reverseAmountOutBN.mul(BigNumber$4.from('100')).div(paymentAmountInBN).abs().toString();
68271
68286
 
68272
- if (divPercent >= 5) {
68287
+ if (divPercent > 5) {
68273
68288
  setPaymentValueLoss(divPercent);
68274
68289
  } else {
68275
68290
  setPaymentValueLoss(null);
@@ -70064,6 +70079,7 @@ let TokenImage = function(props){
70064
70079
 
70065
70080
  return(
70066
70081
  react.createElement('img', {
70082
+ className: props.className ,
70067
70083
  src: src ,
70068
70084
  onError: handleLoadError , __self: this, __source: {fileName: _jsxFileName, lineNumber: 51}}
70069
70085
  )
@@ -70920,11 +70936,11 @@ var PaymentTrackingProvider = (function (props) {
70920
70936
  paymentRoute = _useState6[0],
70921
70937
  setPaymentRoute = _useState6[1];
70922
70938
 
70923
- var _useState7 = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70939
+ var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
70924
70940
  _useState8 = _slicedToArray(_useState7, 1),
70925
70941
  tracking = _useState8[0];
70926
70942
 
70927
- var _useState9 = react.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
70943
+ var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
70928
70944
  _useState10 = _slicedToArray(_useState9, 1),
70929
70945
  polling = _useState10[0];
70930
70946
 
@@ -70992,7 +71008,6 @@ var PaymentTrackingProvider = (function (props) {
70992
71008
 
70993
71009
  var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
70994
71010
  attempt = parseInt(attempt || 1, 10);
70995
- console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
70996
71011
 
70997
71012
  if (attempt < 3) {
70998
71013
  setTimeout(function () {
@@ -71035,9 +71050,7 @@ var PaymentTrackingProvider = (function (props) {
71035
71050
  after_block: afterBlock,
71036
71051
  to_token: paymentRoute.toToken.address
71037
71052
  }).then(function (response) {
71038
- if (response.status == 200) {
71039
- console.log('PAYMENT TRACKING INITIALIZED');
71040
- } else {
71053
+ if (response.status != 200) {
71041
71054
  retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
71042
71055
  }
71043
71056
  })["catch"](function (error) {
@@ -71101,7 +71114,56 @@ var PaymentTrackingProvider = (function (props) {
71101
71114
  };
71102
71115
  }, [polling, transaction, afterBlock, paymentRoute]);
71103
71116
 
71117
+ var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
71118
+ if (attempt > 3) {
71119
+ return;
71120
+ }
71121
+
71122
+ fetch('https://api.depay.fi/v2/payments', {
71123
+ method: 'POST',
71124
+ headers: {
71125
+ 'X-Api-Key': apiKey,
71126
+ 'Content-Type': 'application/json'
71127
+ },
71128
+ body: JSON.stringify({
71129
+ blockchain: transaction.blockchain,
71130
+ transaction: transaction.id,
71131
+ sender: transaction.from.toLowerCase(),
71132
+ nonce: transaction.nonce,
71133
+ receiver: paymentRoute.toAddress,
71134
+ token: paymentRoute.toToken.address,
71135
+ amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
71136
+ confirmations: 1,
71137
+ after_block: afterBlock,
71138
+ uuid: transaction.id,
71139
+ payload: {
71140
+ sender_id: transaction.from.toLowerCase(),
71141
+ sender_token_id: paymentRoute.fromToken.address,
71142
+ sender_amount: formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
71143
+ },
71144
+ fee_amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
71145
+ fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
71146
+ })
71147
+ }).then(function (response) {
71148
+ if (response.status == 200 || response.status == 201) ; else {
71149
+ setTimeout(function () {
71150
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71151
+ }, 3000);
71152
+ }
71153
+ })["catch"](function (error) {
71154
+ setTimeout(function () {
71155
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71156
+ }, 3000);
71157
+ });
71158
+ };
71159
+
71104
71160
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
71161
+ storePayment(transaction, afterBlock, paymentRoute, 1);
71162
+
71163
+ if (tracking == false) {
71164
+ return;
71165
+ }
71166
+
71105
71167
  setTransaction(transaction);
71106
71168
  setAfterBlock(afterBlock);
71107
71169
  setPaymentRoute(paymentRoute);
package/dist/esm/index.js CHANGED
@@ -2317,7 +2317,7 @@ var PaymentProvider = (function (props) {
2317
2317
  var _useContext9 = useContext(PaymentTrackingContext),
2318
2318
  release = _useContext9.release,
2319
2319
  tracking = _useContext9.tracking,
2320
- initializeTracking = _useContext9.initializeTracking;
2320
+ initializePaymentTracking = _useContext9.initializeTracking;
2321
2321
 
2322
2322
  var _useContext10 = useContext(TransactionTrackingContext),
2323
2323
  foundTransaction = _useContext10.foundTransaction,
@@ -2397,10 +2397,7 @@ var PaymentProvider = (function (props) {
2397
2397
  confirmed: paymentConfirmed,
2398
2398
  failed: paymentFailed
2399
2399
  })).then(function (sentTransaction) {
2400
- if (tracking) {
2401
- initializeTracking(sentTransaction, currentBlock, payment.route);
2402
- }
2403
-
2400
+ initializePaymentTracking(sentTransaction, currentBlock, payment.route);
2404
2401
  setTransaction(sentTransaction);
2405
2402
  })["catch"](function (error) {
2406
2403
  console.log('error', error);
@@ -2821,7 +2818,7 @@ var PaymentValueProvider = (function (props) {
2821
2818
  var paymentAmountInBN = ethers.BigNumber.from(payment.route.fromAmount);
2822
2819
  var divPercent = 100 - reverseAmountOutBN.mul(ethers.BigNumber.from('100')).div(paymentAmountInBN).abs().toString();
2823
2820
 
2824
- if (divPercent >= 5) {
2821
+ if (divPercent > 5) {
2825
2822
  setPaymentValueLoss(divPercent);
2826
2823
  } else {
2827
2824
  setPaymentValueLoss(null);
@@ -3758,11 +3755,11 @@ var PaymentTrackingProvider = (function (props) {
3758
3755
  paymentRoute = _useState6[0],
3759
3756
  setPaymentRoute = _useState6[1];
3760
3757
 
3761
- var _useState7 = useState(track && !!(track.endpoint || typeof track.method == 'function')),
3758
+ var _useState7 = useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
3762
3759
  _useState8 = _slicedToArray(_useState7, 1),
3763
3760
  tracking = _useState8[0];
3764
3761
 
3765
- var _useState9 = useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
3762
+ var _useState9 = useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
3766
3763
  _useState10 = _slicedToArray(_useState9, 1),
3767
3764
  polling = _useState10[0];
3768
3765
 
@@ -3830,7 +3827,6 @@ var PaymentTrackingProvider = (function (props) {
3830
3827
 
3831
3828
  var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
3832
3829
  attempt = parseInt(attempt || 1, 10);
3833
- console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
3834
3830
 
3835
3831
  if (attempt < 3) {
3836
3832
  setTimeout(function () {
@@ -3873,9 +3869,7 @@ var PaymentTrackingProvider = (function (props) {
3873
3869
  after_block: afterBlock,
3874
3870
  to_token: paymentRoute.toToken.address
3875
3871
  }).then(function (response) {
3876
- if (response.status == 200) {
3877
- console.log('PAYMENT TRACKING INITIALIZED');
3878
- } else {
3872
+ if (response.status != 200) {
3879
3873
  retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
3880
3874
  }
3881
3875
  })["catch"](function (error) {
@@ -3939,7 +3933,56 @@ var PaymentTrackingProvider = (function (props) {
3939
3933
  };
3940
3934
  }, [polling, transaction, afterBlock, paymentRoute]);
3941
3935
 
3936
+ var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
3937
+ if (attempt > 3) {
3938
+ return;
3939
+ }
3940
+
3941
+ fetch('https://api.depay.fi/v2/payments', {
3942
+ method: 'POST',
3943
+ headers: {
3944
+ 'X-Api-Key': apiKey,
3945
+ 'Content-Type': 'application/json'
3946
+ },
3947
+ body: JSON.stringify({
3948
+ blockchain: transaction.blockchain,
3949
+ transaction: transaction.id,
3950
+ sender: transaction.from.toLowerCase(),
3951
+ nonce: transaction.nonce,
3952
+ receiver: paymentRoute.toAddress,
3953
+ token: paymentRoute.toToken.address,
3954
+ amount: paymentRoute.fee ? ethers.utils.formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : ethers.utils.formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
3955
+ confirmations: 1,
3956
+ after_block: afterBlock,
3957
+ uuid: transaction.id,
3958
+ payload: {
3959
+ sender_id: transaction.from.toLowerCase(),
3960
+ sender_token_id: paymentRoute.fromToken.address,
3961
+ sender_amount: ethers.utils.formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
3962
+ },
3963
+ fee_amount: paymentRoute.fee ? ethers.utils.formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
3964
+ fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
3965
+ })
3966
+ }).then(function (response) {
3967
+ if (response.status == 200 || response.status == 201) ; else {
3968
+ setTimeout(function () {
3969
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
3970
+ }, 3000);
3971
+ }
3972
+ })["catch"](function (error) {
3973
+ setTimeout(function () {
3974
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
3975
+ }, 3000);
3976
+ });
3977
+ };
3978
+
3942
3979
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
3980
+ storePayment(transaction, afterBlock, paymentRoute, 1);
3981
+
3982
+ if (tracking == false) {
3983
+ return;
3984
+ }
3985
+
3943
3986
  setTransaction(transaction);
3944
3987
  setAfterBlock(afterBlock);
3945
3988
  setPaymentRoute(paymentRoute);
@@ -48849,6 +48849,10 @@
48849
48849
  function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
48850
48850
  let connectedInstance;
48851
48851
 
48852
+ const getConnectedInstance = ()=>{
48853
+ return connectedInstance
48854
+ };
48855
+
48852
48856
  class WalletConnectWallet {
48853
48857
 
48854
48858
  static __initStatic() {this.info = {
@@ -48921,6 +48925,10 @@
48921
48925
 
48922
48926
  async connect(options) {
48923
48927
  try {
48928
+ if(this.connector == undefined){
48929
+ this.connector = this.newWalletConnectInstance();
48930
+ }
48931
+
48924
48932
  if(this.connector.connected) {
48925
48933
  await this.connector.killSession();
48926
48934
  connectedInstance = undefined;
@@ -48937,7 +48945,8 @@
48937
48945
  this.connectedChainId = chainId;
48938
48946
 
48939
48947
  return accounts
48940
- } catch (e) {
48948
+ } catch (error) {
48949
+ console.log('WALLETCONNECT ERROR', error);
48941
48950
  return []
48942
48951
  }
48943
48952
  }
@@ -49031,7 +49040,7 @@
49031
49040
  const instances = {};
49032
49041
 
49033
49042
  const getWalletClass = function(){
49034
- if(connectedInstance) {
49043
+ if(getConnectedInstance()) {
49035
49044
  return wallets.WalletConnect
49036
49045
  } else if (typeof window.ethereum === 'object' && window.ethereum.isMetaMask) {
49037
49046
  return wallets.MetaMask
@@ -49046,8 +49055,8 @@
49046
49055
  const walletClass = getWalletClass();
49047
49056
  const existingInstance = instances[walletClass];
49048
49057
 
49049
- if(connectedInstance) {
49050
- return connectedInstance
49058
+ if(getConnectedInstance()) {
49059
+ return getConnectedInstance()
49051
49060
  } else if(existingInstance) {
49052
49061
  return existingInstance
49053
49062
  } else if(walletClass) {
@@ -55321,17 +55330,21 @@
55321
55330
  if (this.address == CONSTANTS$2[this.blockchain].NATIVE) {
55322
55331
  return CONSTANTS$2[this.blockchain].DECIMALS
55323
55332
  }
55324
- return await request(
55325
- {
55326
- blockchain: this.blockchain,
55327
- address: this.address,
55328
- method: 'decimals',
55329
- },
55330
- {
55331
- api: Token[this.blockchain].DEFAULT,
55332
- cache: 86400000, // 1 day
55333
- },
55334
- )
55333
+ let decimals = 0;
55334
+ try {
55335
+ decimals = await request(
55336
+ {
55337
+ blockchain: this.blockchain,
55338
+ address: this.address,
55339
+ method: 'decimals',
55340
+ },
55341
+ {
55342
+ api: Token[this.blockchain].DEFAULT,
55343
+ cache: 86400000, // 1 day
55344
+ },
55345
+ );
55346
+ } catch (e) {}
55347
+ return decimals
55335
55348
  }
55336
55349
 
55337
55350
  async symbol() {
@@ -62477,7 +62490,7 @@
62477
62490
  var _useContext9 = react.useContext(PaymentTrackingContext),
62478
62491
  release = _useContext9.release,
62479
62492
  tracking = _useContext9.tracking,
62480
- initializeTracking = _useContext9.initializeTracking;
62493
+ initializePaymentTracking = _useContext9.initializeTracking;
62481
62494
 
62482
62495
  var _useContext10 = react.useContext(TransactionTrackingContext),
62483
62496
  foundTransaction = _useContext10.foundTransaction,
@@ -62557,10 +62570,7 @@
62557
62570
  confirmed: paymentConfirmed,
62558
62571
  failed: paymentFailed
62559
62572
  })).then(function (sentTransaction) {
62560
- if (tracking) {
62561
- initializeTracking(sentTransaction, currentBlock, payment.route);
62562
- }
62563
-
62573
+ initializePaymentTracking(sentTransaction, currentBlock, payment.route);
62564
62574
  setTransaction(sentTransaction);
62565
62575
  })["catch"](function (error) {
62566
62576
  console.log('error', error);
@@ -67693,10 +67703,10 @@
67693
67703
  this.fromAddress = fromAddress;
67694
67704
  this.fromToken = fromToken;
67695
67705
  this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
67696
- this.fromDecimals = _optionalChain([fromDecimals, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67706
+ this.fromDecimals = fromDecimals;
67697
67707
  this.fromBalance = 0;
67698
67708
  this.toToken = toToken;
67699
- this.toAmount = _optionalChain([toAmount, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]);
67709
+ this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67700
67710
  this.toDecimals = toDecimals;
67701
67711
  this.toAddress = toAddress;
67702
67712
  this.toContract = toContract;
@@ -67760,12 +67770,14 @@
67760
67770
  if(configuration.token && configuration.amount) {
67761
67771
  let blockchain = configuration.blockchain;
67762
67772
  let toToken = new Token({ blockchain, address: configuration.token });
67773
+ let fromDecimals = await fromToken.decimals();
67763
67774
  let toDecimals = await toToken.decimals();
67764
67775
  let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
67765
67776
 
67766
67777
  return new PaymentRoute({
67767
67778
  blockchain,
67768
67779
  fromToken,
67780
+ fromDecimals,
67769
67781
  toToken,
67770
67782
  toAmount,
67771
67783
  toDecimals,
@@ -67810,7 +67822,7 @@
67810
67822
  .then(addApproval)
67811
67823
  .then(sortPaymentRoutes)
67812
67824
  .then((routes)=>addTransactions({ routes, event, fee }))
67813
- .then(addFromAmount)
67825
+ .then(addRouteAmounts)
67814
67826
  .then(filterDuplicateFromTokens);
67815
67827
 
67816
67828
  return paymentRoutes
@@ -67943,16 +67955,19 @@
67943
67955
  })
67944
67956
  };
67945
67957
 
67946
- let addFromAmount = (routes)=> {
67958
+ let addRouteAmounts = (routes)=> {
67947
67959
  return routes.map((route)=>{
67948
67960
  if(route.directTransfer && !route.fee) {
67949
67961
  if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
67950
67962
  route.fromAmount = route.transaction.value;
67963
+ route.toAmount = route.transaction.value;
67951
67964
  } else {
67952
67965
  route.fromAmount = route.transaction.params[1];
67966
+ route.toAmount = route.transaction.params[1];
67953
67967
  }
67954
67968
  } else {
67955
67969
  route.fromAmount = route.transaction.params.amounts[0];
67970
+ route.toAmount = route.transaction.params.amounts[1];
67956
67971
  }
67957
67972
  return route
67958
67973
  })
@@ -68275,7 +68290,7 @@
68275
68290
  var paymentAmountInBN = BigNumber$4.from(payment.route.fromAmount);
68276
68291
  var divPercent = 100 - reverseAmountOutBN.mul(BigNumber$4.from('100')).div(paymentAmountInBN).abs().toString();
68277
68292
 
68278
- if (divPercent >= 5) {
68293
+ if (divPercent > 5) {
68279
68294
  setPaymentValueLoss(divPercent);
68280
68295
  } else {
68281
68296
  setPaymentValueLoss(null);
@@ -70070,6 +70085,7 @@
70070
70085
 
70071
70086
  return(
70072
70087
  react.createElement('img', {
70088
+ className: props.className ,
70073
70089
  src: src ,
70074
70090
  onError: handleLoadError , __self: this, __source: {fileName: _jsxFileName, lineNumber: 51}}
70075
70091
  )
@@ -70926,11 +70942,11 @@
70926
70942
  paymentRoute = _useState6[0],
70927
70943
  setPaymentRoute = _useState6[1];
70928
70944
 
70929
- var _useState7 = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70945
+ var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
70930
70946
  _useState8 = _slicedToArray(_useState7, 1),
70931
70947
  tracking = _useState8[0];
70932
70948
 
70933
- var _useState9 = react.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
70949
+ var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
70934
70950
  _useState10 = _slicedToArray(_useState9, 1),
70935
70951
  polling = _useState10[0];
70936
70952
 
@@ -70998,7 +71014,6 @@
70998
71014
 
70999
71015
  var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
71000
71016
  attempt = parseInt(attempt || 1, 10);
71001
- console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
71002
71017
 
71003
71018
  if (attempt < 3) {
71004
71019
  setTimeout(function () {
@@ -71041,9 +71056,7 @@
71041
71056
  after_block: afterBlock,
71042
71057
  to_token: paymentRoute.toToken.address
71043
71058
  }).then(function (response) {
71044
- if (response.status == 200) {
71045
- console.log('PAYMENT TRACKING INITIALIZED');
71046
- } else {
71059
+ if (response.status != 200) {
71047
71060
  retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
71048
71061
  }
71049
71062
  })["catch"](function (error) {
@@ -71107,7 +71120,56 @@
71107
71120
  };
71108
71121
  }, [polling, transaction, afterBlock, paymentRoute]);
71109
71122
 
71123
+ var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
71124
+ if (attempt > 3) {
71125
+ return;
71126
+ }
71127
+
71128
+ fetch('https://api.depay.fi/v2/payments', {
71129
+ method: 'POST',
71130
+ headers: {
71131
+ 'X-Api-Key': apiKey,
71132
+ 'Content-Type': 'application/json'
71133
+ },
71134
+ body: JSON.stringify({
71135
+ blockchain: transaction.blockchain,
71136
+ transaction: transaction.id,
71137
+ sender: transaction.from.toLowerCase(),
71138
+ nonce: transaction.nonce,
71139
+ receiver: paymentRoute.toAddress,
71140
+ token: paymentRoute.toToken.address,
71141
+ amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
71142
+ confirmations: 1,
71143
+ after_block: afterBlock,
71144
+ uuid: transaction.id,
71145
+ payload: {
71146
+ sender_id: transaction.from.toLowerCase(),
71147
+ sender_token_id: paymentRoute.fromToken.address,
71148
+ sender_amount: formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
71149
+ },
71150
+ fee_amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
71151
+ fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
71152
+ })
71153
+ }).then(function (response) {
71154
+ if (response.status == 200 || response.status == 201) ; else {
71155
+ setTimeout(function () {
71156
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71157
+ }, 3000);
71158
+ }
71159
+ })["catch"](function (error) {
71160
+ setTimeout(function () {
71161
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71162
+ }, 3000);
71163
+ });
71164
+ };
71165
+
71110
71166
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
71167
+ storePayment(transaction, afterBlock, paymentRoute, 1);
71168
+
71169
+ if (tracking == false) {
71170
+ return;
71171
+ }
71172
+
71111
71173
  setTransaction(transaction);
71112
71174
  setAfterBlock(afterBlock);
71113
71175
  setPaymentRoute(paymentRoute);
package/dist/umd/index.js CHANGED
@@ -2312,7 +2312,7 @@
2312
2312
  var _useContext9 = React.useContext(PaymentTrackingContext),
2313
2313
  release = _useContext9.release,
2314
2314
  tracking = _useContext9.tracking,
2315
- initializeTracking = _useContext9.initializeTracking;
2315
+ initializePaymentTracking = _useContext9.initializeTracking;
2316
2316
 
2317
2317
  var _useContext10 = React.useContext(TransactionTrackingContext),
2318
2318
  foundTransaction = _useContext10.foundTransaction,
@@ -2392,10 +2392,7 @@
2392
2392
  confirmed: paymentConfirmed,
2393
2393
  failed: paymentFailed
2394
2394
  })).then(function (sentTransaction) {
2395
- if (tracking) {
2396
- initializeTracking(sentTransaction, currentBlock, payment.route);
2397
- }
2398
-
2395
+ initializePaymentTracking(sentTransaction, currentBlock, payment.route);
2399
2396
  setTransaction(sentTransaction);
2400
2397
  })["catch"](function (error) {
2401
2398
  console.log('error', error);
@@ -2816,7 +2813,7 @@
2816
2813
  var paymentAmountInBN = ethers.ethers.BigNumber.from(payment.route.fromAmount);
2817
2814
  var divPercent = 100 - reverseAmountOutBN.mul(ethers.ethers.BigNumber.from('100')).div(paymentAmountInBN).abs().toString();
2818
2815
 
2819
- if (divPercent >= 5) {
2816
+ if (divPercent > 5) {
2820
2817
  setPaymentValueLoss(divPercent);
2821
2818
  } else {
2822
2819
  setPaymentValueLoss(null);
@@ -3753,11 +3750,11 @@
3753
3750
  paymentRoute = _useState6[0],
3754
3751
  setPaymentRoute = _useState6[1];
3755
3752
 
3756
- var _useState7 = React.useState(track && !!(track.endpoint || typeof track.method == 'function')),
3753
+ var _useState7 = React.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
3757
3754
  _useState8 = _slicedToArray(_useState7, 1),
3758
3755
  tracking = _useState8[0];
3759
3756
 
3760
- var _useState9 = React.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
3757
+ var _useState9 = React.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
3761
3758
  _useState10 = _slicedToArray(_useState9, 1),
3762
3759
  polling = _useState10[0];
3763
3760
 
@@ -3825,7 +3822,6 @@
3825
3822
 
3826
3823
  var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
3827
3824
  attempt = parseInt(attempt || 1, 10);
3828
- console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
3829
3825
 
3830
3826
  if (attempt < 3) {
3831
3827
  setTimeout(function () {
@@ -3868,9 +3864,7 @@
3868
3864
  after_block: afterBlock,
3869
3865
  to_token: paymentRoute.toToken.address
3870
3866
  }).then(function (response) {
3871
- if (response.status == 200) {
3872
- console.log('PAYMENT TRACKING INITIALIZED');
3873
- } else {
3867
+ if (response.status != 200) {
3874
3868
  retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
3875
3869
  }
3876
3870
  })["catch"](function (error) {
@@ -3934,7 +3928,56 @@
3934
3928
  };
3935
3929
  }, [polling, transaction, afterBlock, paymentRoute]);
3936
3930
 
3931
+ var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
3932
+ if (attempt > 3) {
3933
+ return;
3934
+ }
3935
+
3936
+ fetch('https://api.depay.fi/v2/payments', {
3937
+ method: 'POST',
3938
+ headers: {
3939
+ 'X-Api-Key': apiKey,
3940
+ 'Content-Type': 'application/json'
3941
+ },
3942
+ body: JSON.stringify({
3943
+ blockchain: transaction.blockchain,
3944
+ transaction: transaction.id,
3945
+ sender: transaction.from.toLowerCase(),
3946
+ nonce: transaction.nonce,
3947
+ receiver: paymentRoute.toAddress,
3948
+ token: paymentRoute.toToken.address,
3949
+ amount: paymentRoute.fee ? ethers.ethers.utils.formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : ethers.ethers.utils.formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
3950
+ confirmations: 1,
3951
+ after_block: afterBlock,
3952
+ uuid: transaction.id,
3953
+ payload: {
3954
+ sender_id: transaction.from.toLowerCase(),
3955
+ sender_token_id: paymentRoute.fromToken.address,
3956
+ sender_amount: ethers.ethers.utils.formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
3957
+ },
3958
+ fee_amount: paymentRoute.fee ? ethers.ethers.utils.formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
3959
+ fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
3960
+ })
3961
+ }).then(function (response) {
3962
+ if (response.status == 200 || response.status == 201) ; else {
3963
+ setTimeout(function () {
3964
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
3965
+ }, 3000);
3966
+ }
3967
+ })["catch"](function (error) {
3968
+ setTimeout(function () {
3969
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
3970
+ }, 3000);
3971
+ });
3972
+ };
3973
+
3937
3974
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
3975
+ storePayment(transaction, afterBlock, paymentRoute, 1);
3976
+
3977
+ if (tracking == false) {
3978
+ return;
3979
+ }
3980
+
3938
3981
  setTransaction(transaction);
3939
3982
  setAfterBlock(afterBlock);
3940
3983
  setPaymentRoute(paymentRoute);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "6.15.0",
4
+ "version": "6.16.3",
5
5
  "description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
6
6
  "main": "./dist/umd/index.js",
7
7
  "module": "./dist/esm/index.js",
@@ -43,9 +43,9 @@
43
43
  "@depay/web3-client": "^8.0.0",
44
44
  "@depay/web3-constants": "^5.0.0",
45
45
  "@depay/web3-exchanges": "^8.1.0",
46
- "@depay/web3-payments": "^9.3.0",
47
- "@depay/web3-tokens": "^8.0.0",
48
- "@depay/web3-wallets": "^9.0.0",
46
+ "@depay/web3-payments": "^9.3.3",
47
+ "@depay/web3-tokens": "^8.0.1",
48
+ "@depay/web3-wallets": "^9.0.2",
49
49
  "decimal.js": "^10.3.1",
50
50
  "react-rangeslider": "^2.2.0"
51
51
  },
@@ -60,7 +60,7 @@
60
60
  "@babel/preset-env": "^7.12.7",
61
61
  "@babel/preset-react": "^7.12.7",
62
62
  "@cypress/react": "^5.9.1",
63
- "@depay/web3-mock": "^11.6.0",
63
+ "@depay/web3-mock": "^11.6.2",
64
64
  "@rollup/plugin-babel": "^5.3.0",
65
65
  "@rollup/plugin-commonjs": "^17.1.0",
66
66
  "@rollup/plugin-node-resolve": "^11.1.1",