@depay/widgets 6.15.0 → 6.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55315,17 +55315,21 @@ class Token {
55315
55315
  if (this.address == CONSTANTS$2[this.blockchain].NATIVE) {
55316
55316
  return CONSTANTS$2[this.blockchain].DECIMALS
55317
55317
  }
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
- )
55318
+ let decimals = 0;
55319
+ try {
55320
+ decimals = await request(
55321
+ {
55322
+ blockchain: this.blockchain,
55323
+ address: this.address,
55324
+ method: 'decimals',
55325
+ },
55326
+ {
55327
+ api: Token[this.blockchain].DEFAULT,
55328
+ cache: 86400000, // 1 day
55329
+ },
55330
+ );
55331
+ } catch (e) {}
55332
+ return decimals
55329
55333
  }
55330
55334
 
55331
55335
  async symbol() {
@@ -62471,7 +62475,7 @@ var PaymentProvider = (function (props) {
62471
62475
  var _useContext9 = react.useContext(PaymentTrackingContext),
62472
62476
  release = _useContext9.release,
62473
62477
  tracking = _useContext9.tracking,
62474
- initializeTracking = _useContext9.initializeTracking;
62478
+ initializePaymentTracking = _useContext9.initializeTracking;
62475
62479
 
62476
62480
  var _useContext10 = react.useContext(TransactionTrackingContext),
62477
62481
  foundTransaction = _useContext10.foundTransaction,
@@ -62551,10 +62555,7 @@ var PaymentProvider = (function (props) {
62551
62555
  confirmed: paymentConfirmed,
62552
62556
  failed: paymentFailed
62553
62557
  })).then(function (sentTransaction) {
62554
- if (tracking) {
62555
- initializeTracking(sentTransaction, currentBlock, payment.route);
62556
- }
62557
-
62558
+ initializePaymentTracking(sentTransaction, currentBlock, payment.route);
62558
62559
  setTransaction(sentTransaction);
62559
62560
  })["catch"](function (error) {
62560
62561
  console.log('error', error);
@@ -67687,10 +67688,10 @@ class PaymentRoute {
67687
67688
  this.fromAddress = fromAddress;
67688
67689
  this.fromToken = fromToken;
67689
67690
  this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
67690
- this.fromDecimals = _optionalChain([fromDecimals, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67691
+ this.fromDecimals = fromDecimals;
67691
67692
  this.fromBalance = 0;
67692
67693
  this.toToken = toToken;
67693
- this.toAmount = _optionalChain([toAmount, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]);
67694
+ this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67694
67695
  this.toDecimals = toDecimals;
67695
67696
  this.toAddress = toAddress;
67696
67697
  this.toContract = toContract;
@@ -67754,12 +67755,14 @@ function convertToRoutes({ tokens, accept }) {
67754
67755
  if(configuration.token && configuration.amount) {
67755
67756
  let blockchain = configuration.blockchain;
67756
67757
  let toToken = new Token({ blockchain, address: configuration.token });
67758
+ let fromDecimals = await fromToken.decimals();
67757
67759
  let toDecimals = await toToken.decimals();
67758
67760
  let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
67759
67761
 
67760
67762
  return new PaymentRoute({
67761
67763
  blockchain,
67762
67764
  fromToken,
67765
+ fromDecimals,
67763
67766
  toToken,
67764
67767
  toAmount,
67765
67768
  toDecimals,
@@ -67804,7 +67807,7 @@ async function route({ accept, whitelist, blacklist, apiKey, event, fee }) {
67804
67807
  .then(addApproval)
67805
67808
  .then(sortPaymentRoutes)
67806
67809
  .then((routes)=>addTransactions({ routes, event, fee }))
67807
- .then(addFromAmount)
67810
+ .then(addRouteAmounts)
67808
67811
  .then(filterDuplicateFromTokens);
67809
67812
 
67810
67813
  return paymentRoutes
@@ -67937,16 +67940,19 @@ let addDirectTransferStatus = (routes) => {
67937
67940
  })
67938
67941
  };
67939
67942
 
67940
- let addFromAmount = (routes)=> {
67943
+ let addRouteAmounts = (routes)=> {
67941
67944
  return routes.map((route)=>{
67942
67945
  if(route.directTransfer && !route.fee) {
67943
67946
  if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
67944
67947
  route.fromAmount = route.transaction.value;
67948
+ route.toAmount = route.transaction.value;
67945
67949
  } else {
67946
67950
  route.fromAmount = route.transaction.params[1];
67951
+ route.toAmount = route.transaction.params[1];
67947
67952
  }
67948
67953
  } else {
67949
67954
  route.fromAmount = route.transaction.params.amounts[0];
67955
+ route.toAmount = route.transaction.params.amounts[1];
67950
67956
  }
67951
67957
  return route
67952
67958
  })
@@ -70920,11 +70926,11 @@ var PaymentTrackingProvider = (function (props) {
70920
70926
  paymentRoute = _useState6[0],
70921
70927
  setPaymentRoute = _useState6[1];
70922
70928
 
70923
- var _useState7 = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70929
+ var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
70924
70930
  _useState8 = _slicedToArray(_useState7, 1),
70925
70931
  tracking = _useState8[0];
70926
70932
 
70927
- var _useState9 = react.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
70933
+ var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
70928
70934
  _useState10 = _slicedToArray(_useState9, 1),
70929
70935
  polling = _useState10[0];
70930
70936
 
@@ -70992,7 +70998,6 @@ var PaymentTrackingProvider = (function (props) {
70992
70998
 
70993
70999
  var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
70994
71000
  attempt = parseInt(attempt || 1, 10);
70995
- console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
70996
71001
 
70997
71002
  if (attempt < 3) {
70998
71003
  setTimeout(function () {
@@ -71035,9 +71040,7 @@ var PaymentTrackingProvider = (function (props) {
71035
71040
  after_block: afterBlock,
71036
71041
  to_token: paymentRoute.toToken.address
71037
71042
  }).then(function (response) {
71038
- if (response.status == 200) {
71039
- console.log('PAYMENT TRACKING INITIALIZED');
71040
- } else {
71043
+ if (response.status != 200) {
71041
71044
  retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
71042
71045
  }
71043
71046
  })["catch"](function (error) {
@@ -71101,7 +71104,56 @@ var PaymentTrackingProvider = (function (props) {
71101
71104
  };
71102
71105
  }, [polling, transaction, afterBlock, paymentRoute]);
71103
71106
 
71107
+ var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
71108
+ if (attempt > 3) {
71109
+ return;
71110
+ }
71111
+
71112
+ fetch('https://api.depay.fi/v2/payments', {
71113
+ method: 'POST',
71114
+ headers: {
71115
+ 'X-Api-Key': apiKey,
71116
+ 'Content-Type': 'application/json'
71117
+ },
71118
+ body: JSON.stringify({
71119
+ blockchain: transaction.blockchain,
71120
+ transaction: transaction.id,
71121
+ sender: transaction.from.toLowerCase(),
71122
+ nonce: transaction.nonce,
71123
+ receiver: paymentRoute.toAddress,
71124
+ token: paymentRoute.toToken.address,
71125
+ amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
71126
+ confirmations: 1,
71127
+ after_block: afterBlock,
71128
+ uuid: transaction.id,
71129
+ payload: {
71130
+ sender_id: transaction.from.toLowerCase(),
71131
+ sender_token_id: paymentRoute.fromToken.address,
71132
+ sender_amount: formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
71133
+ },
71134
+ fee_amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
71135
+ fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
71136
+ })
71137
+ }).then(function (response) {
71138
+ if (response.status == 200 || response.status == 201) ; else {
71139
+ setTimeout(function () {
71140
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71141
+ }, 3000);
71142
+ }
71143
+ })["catch"](function (error) {
71144
+ setTimeout(function () {
71145
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71146
+ }, 3000);
71147
+ });
71148
+ };
71149
+
71104
71150
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
71151
+ storePayment(transaction, afterBlock, paymentRoute, 1);
71152
+
71153
+ if (tracking == false) {
71154
+ return;
71155
+ }
71156
+
71105
71157
  setTransaction(transaction);
71106
71158
  setAfterBlock(afterBlock);
71107
71159
  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);
@@ -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);
@@ -55321,17 +55321,21 @@
55321
55321
  if (this.address == CONSTANTS$2[this.blockchain].NATIVE) {
55322
55322
  return CONSTANTS$2[this.blockchain].DECIMALS
55323
55323
  }
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
- )
55324
+ let decimals = 0;
55325
+ try {
55326
+ decimals = await request(
55327
+ {
55328
+ blockchain: this.blockchain,
55329
+ address: this.address,
55330
+ method: 'decimals',
55331
+ },
55332
+ {
55333
+ api: Token[this.blockchain].DEFAULT,
55334
+ cache: 86400000, // 1 day
55335
+ },
55336
+ );
55337
+ } catch (e) {}
55338
+ return decimals
55335
55339
  }
55336
55340
 
55337
55341
  async symbol() {
@@ -62477,7 +62481,7 @@
62477
62481
  var _useContext9 = react.useContext(PaymentTrackingContext),
62478
62482
  release = _useContext9.release,
62479
62483
  tracking = _useContext9.tracking,
62480
- initializeTracking = _useContext9.initializeTracking;
62484
+ initializePaymentTracking = _useContext9.initializeTracking;
62481
62485
 
62482
62486
  var _useContext10 = react.useContext(TransactionTrackingContext),
62483
62487
  foundTransaction = _useContext10.foundTransaction,
@@ -62557,10 +62561,7 @@
62557
62561
  confirmed: paymentConfirmed,
62558
62562
  failed: paymentFailed
62559
62563
  })).then(function (sentTransaction) {
62560
- if (tracking) {
62561
- initializeTracking(sentTransaction, currentBlock, payment.route);
62562
- }
62563
-
62564
+ initializePaymentTracking(sentTransaction, currentBlock, payment.route);
62564
62565
  setTransaction(sentTransaction);
62565
62566
  })["catch"](function (error) {
62566
62567
  console.log('error', error);
@@ -67693,10 +67694,10 @@
67693
67694
  this.fromAddress = fromAddress;
67694
67695
  this.fromToken = fromToken;
67695
67696
  this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
67696
- this.fromDecimals = _optionalChain([fromDecimals, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67697
+ this.fromDecimals = fromDecimals;
67697
67698
  this.fromBalance = 0;
67698
67699
  this.toToken = toToken;
67699
- this.toAmount = _optionalChain([toAmount, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]);
67700
+ this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
67700
67701
  this.toDecimals = toDecimals;
67701
67702
  this.toAddress = toAddress;
67702
67703
  this.toContract = toContract;
@@ -67760,12 +67761,14 @@
67760
67761
  if(configuration.token && configuration.amount) {
67761
67762
  let blockchain = configuration.blockchain;
67762
67763
  let toToken = new Token({ blockchain, address: configuration.token });
67764
+ let fromDecimals = await fromToken.decimals();
67763
67765
  let toDecimals = await toToken.decimals();
67764
67766
  let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
67765
67767
 
67766
67768
  return new PaymentRoute({
67767
67769
  blockchain,
67768
67770
  fromToken,
67771
+ fromDecimals,
67769
67772
  toToken,
67770
67773
  toAmount,
67771
67774
  toDecimals,
@@ -67810,7 +67813,7 @@
67810
67813
  .then(addApproval)
67811
67814
  .then(sortPaymentRoutes)
67812
67815
  .then((routes)=>addTransactions({ routes, event, fee }))
67813
- .then(addFromAmount)
67816
+ .then(addRouteAmounts)
67814
67817
  .then(filterDuplicateFromTokens);
67815
67818
 
67816
67819
  return paymentRoutes
@@ -67943,16 +67946,19 @@
67943
67946
  })
67944
67947
  };
67945
67948
 
67946
- let addFromAmount = (routes)=> {
67949
+ let addRouteAmounts = (routes)=> {
67947
67950
  return routes.map((route)=>{
67948
67951
  if(route.directTransfer && !route.fee) {
67949
67952
  if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
67950
67953
  route.fromAmount = route.transaction.value;
67954
+ route.toAmount = route.transaction.value;
67951
67955
  } else {
67952
67956
  route.fromAmount = route.transaction.params[1];
67957
+ route.toAmount = route.transaction.params[1];
67953
67958
  }
67954
67959
  } else {
67955
67960
  route.fromAmount = route.transaction.params.amounts[0];
67961
+ route.toAmount = route.transaction.params.amounts[1];
67956
67962
  }
67957
67963
  return route
67958
67964
  })
@@ -70926,11 +70932,11 @@
70926
70932
  paymentRoute = _useState6[0],
70927
70933
  setPaymentRoute = _useState6[1];
70928
70934
 
70929
- var _useState7 = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70935
+ var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
70930
70936
  _useState8 = _slicedToArray(_useState7, 1),
70931
70937
  tracking = _useState8[0];
70932
70938
 
70933
- var _useState9 = react.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
70939
+ var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
70934
70940
  _useState10 = _slicedToArray(_useState9, 1),
70935
70941
  polling = _useState10[0];
70936
70942
 
@@ -70998,7 +71004,6 @@
70998
71004
 
70999
71005
  var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
71000
71006
  attempt = parseInt(attempt || 1, 10);
71001
- console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
71002
71007
 
71003
71008
  if (attempt < 3) {
71004
71009
  setTimeout(function () {
@@ -71041,9 +71046,7 @@
71041
71046
  after_block: afterBlock,
71042
71047
  to_token: paymentRoute.toToken.address
71043
71048
  }).then(function (response) {
71044
- if (response.status == 200) {
71045
- console.log('PAYMENT TRACKING INITIALIZED');
71046
- } else {
71049
+ if (response.status != 200) {
71047
71050
  retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
71048
71051
  }
71049
71052
  })["catch"](function (error) {
@@ -71107,7 +71110,56 @@
71107
71110
  };
71108
71111
  }, [polling, transaction, afterBlock, paymentRoute]);
71109
71112
 
71113
+ var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
71114
+ if (attempt > 3) {
71115
+ return;
71116
+ }
71117
+
71118
+ fetch('https://api.depay.fi/v2/payments', {
71119
+ method: 'POST',
71120
+ headers: {
71121
+ 'X-Api-Key': apiKey,
71122
+ 'Content-Type': 'application/json'
71123
+ },
71124
+ body: JSON.stringify({
71125
+ blockchain: transaction.blockchain,
71126
+ transaction: transaction.id,
71127
+ sender: transaction.from.toLowerCase(),
71128
+ nonce: transaction.nonce,
71129
+ receiver: paymentRoute.toAddress,
71130
+ token: paymentRoute.toToken.address,
71131
+ amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
71132
+ confirmations: 1,
71133
+ after_block: afterBlock,
71134
+ uuid: transaction.id,
71135
+ payload: {
71136
+ sender_id: transaction.from.toLowerCase(),
71137
+ sender_token_id: paymentRoute.fromToken.address,
71138
+ sender_amount: formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
71139
+ },
71140
+ fee_amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
71141
+ fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
71142
+ })
71143
+ }).then(function (response) {
71144
+ if (response.status == 200 || response.status == 201) ; else {
71145
+ setTimeout(function () {
71146
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71147
+ }, 3000);
71148
+ }
71149
+ })["catch"](function (error) {
71150
+ setTimeout(function () {
71151
+ storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
71152
+ }, 3000);
71153
+ });
71154
+ };
71155
+
71110
71156
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
71157
+ storePayment(transaction, afterBlock, paymentRoute, 1);
71158
+
71159
+ if (tracking == false) {
71160
+ return;
71161
+ }
71162
+
71111
71163
  setTransaction(transaction);
71112
71164
  setAfterBlock(afterBlock);
71113
71165
  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);
@@ -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.0",
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,8 +43,8 @@
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",
46
+ "@depay/web3-payments": "^9.3.3",
47
+ "@depay/web3-tokens": "^8.0.1",
48
48
  "@depay/web3-wallets": "^9.0.0",
49
49
  "decimal.js": "^10.3.1",
50
50
  "react-rangeslider": "^2.2.0"
@@ -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",