@depay/widgets 6.13.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.
- package/README.md +19 -0
- package/dist/esm/index.bundle.js +213 -79
- package/dist/esm/index.js +128 -39
- package/dist/umd/index.bundle.js +213 -79
- package/dist/umd/index.js +128 -39
- package/package.json +4 -4
package/dist/umd/index.bundle.js
CHANGED
|
@@ -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
|
-
|
|
55325
|
-
|
|
55326
|
-
|
|
55327
|
-
|
|
55328
|
-
|
|
55329
|
-
|
|
55330
|
-
|
|
55331
|
-
|
|
55332
|
-
|
|
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() {
|
|
@@ -61724,13 +61728,14 @@
|
|
|
61724
61728
|
var ChangableAmountProvider = (function (props) {
|
|
61725
61729
|
var configurationsMissAmounts = function configurationsMissAmounts(configurations) {
|
|
61726
61730
|
return !configurations.every(function (configuration) {
|
|
61727
|
-
return typeof configuration.amount != 'undefined';
|
|
61731
|
+
return typeof configuration.amount != 'undefined' || typeof configuration.fromAmount != 'undefined';
|
|
61728
61732
|
});
|
|
61729
61733
|
};
|
|
61730
61734
|
|
|
61731
61735
|
var _useContext = react.useContext(ConfigurationContext),
|
|
61732
|
-
amountConfiguration = _useContext.amount
|
|
61733
|
-
|
|
61736
|
+
amountConfiguration = _useContext.amount;
|
|
61737
|
+
_useContext.toAmount;
|
|
61738
|
+
var recover = _useContext.recover;
|
|
61734
61739
|
|
|
61735
61740
|
var _useState = react.useState(recover == undefined ? configurationsMissAmounts(props.accept) : false),
|
|
61736
61741
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -62476,7 +62481,7 @@
|
|
|
62476
62481
|
var _useContext9 = react.useContext(PaymentTrackingContext),
|
|
62477
62482
|
release = _useContext9.release,
|
|
62478
62483
|
tracking = _useContext9.tracking,
|
|
62479
|
-
|
|
62484
|
+
initializePaymentTracking = _useContext9.initializeTracking;
|
|
62480
62485
|
|
|
62481
62486
|
var _useContext10 = react.useContext(TransactionTrackingContext),
|
|
62482
62487
|
foundTransaction = _useContext10.foundTransaction,
|
|
@@ -62556,10 +62561,7 @@
|
|
|
62556
62561
|
confirmed: paymentConfirmed,
|
|
62557
62562
|
failed: paymentFailed
|
|
62558
62563
|
})).then(function (sentTransaction) {
|
|
62559
|
-
|
|
62560
|
-
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
62561
|
-
}
|
|
62562
|
-
|
|
62564
|
+
initializePaymentTracking(sentTransaction, currentBlock, payment.route);
|
|
62563
62565
|
setTransaction(sentTransaction);
|
|
62564
62566
|
})["catch"](function (error) {
|
|
62565
62567
|
console.log('error', error);
|
|
@@ -67687,14 +67689,16 @@
|
|
|
67687
67689
|
|
|
67688
67690
|
function _optionalChain(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; }
|
|
67689
67691
|
class PaymentRoute {
|
|
67690
|
-
constructor({ blockchain, fromToken, toToken, toDecimals, toAmount,
|
|
67692
|
+
constructor({ blockchain, fromAddress, fromToken, fromDecimals, fromAmount, toToken, toDecimals, toAmount, toAddress, toContract }) {
|
|
67691
67693
|
this.blockchain = blockchain;
|
|
67694
|
+
this.fromAddress = fromAddress;
|
|
67692
67695
|
this.fromToken = fromToken;
|
|
67696
|
+
this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
|
|
67697
|
+
this.fromDecimals = fromDecimals;
|
|
67693
67698
|
this.fromBalance = 0;
|
|
67694
67699
|
this.toToken = toToken;
|
|
67700
|
+
this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
67695
67701
|
this.toDecimals = toDecimals;
|
|
67696
|
-
this.toAmount = _optionalChain([toAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
|
|
67697
|
-
this.fromAddress = fromAddress;
|
|
67698
67702
|
this.toAddress = toAddress;
|
|
67699
67703
|
this.toContract = toContract;
|
|
67700
67704
|
this.exchangeRoutes = [];
|
|
@@ -67754,22 +67758,45 @@
|
|
|
67754
67758
|
return Promise.all(tokens.map(async (fromToken)=>{
|
|
67755
67759
|
let relevantConfigurations = accept.filter((configuration)=>(configuration.blockchain == fromToken.blockchain));
|
|
67756
67760
|
return Promise.all(relevantConfigurations.map(async (configuration)=>{
|
|
67757
|
-
|
|
67758
|
-
|
|
67759
|
-
|
|
67760
|
-
|
|
67761
|
-
|
|
67762
|
-
|
|
67763
|
-
|
|
67764
|
-
|
|
67765
|
-
|
|
67766
|
-
|
|
67767
|
-
|
|
67768
|
-
|
|
67769
|
-
|
|
67770
|
-
|
|
67761
|
+
if(configuration.token && configuration.amount) {
|
|
67762
|
+
let blockchain = configuration.blockchain;
|
|
67763
|
+
let toToken = new Token({ blockchain, address: configuration.token });
|
|
67764
|
+
let fromDecimals = await fromToken.decimals();
|
|
67765
|
+
let toDecimals = await toToken.decimals();
|
|
67766
|
+
let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
|
|
67767
|
+
|
|
67768
|
+
return new PaymentRoute({
|
|
67769
|
+
blockchain,
|
|
67770
|
+
fromToken,
|
|
67771
|
+
fromDecimals,
|
|
67772
|
+
toToken,
|
|
67773
|
+
toAmount,
|
|
67774
|
+
toDecimals,
|
|
67775
|
+
fromAddress: configuration.fromAddress,
|
|
67776
|
+
toAddress: configuration.toAddress,
|
|
67777
|
+
toContract: configuration.toContract
|
|
67778
|
+
})
|
|
67779
|
+
} else if(configuration.fromToken && configuration.fromAmount && fromToken.address.toLowerCase() == configuration.fromToken.toLowerCase()) {
|
|
67780
|
+
let blockchain = configuration.blockchain;
|
|
67781
|
+
let fromAmount = (await fromToken.BigNumber(configuration.fromAmount)).toString();
|
|
67782
|
+
let fromDecimals = await fromToken.decimals();
|
|
67783
|
+
let toToken = new Token({ blockchain, address: configuration.toToken });
|
|
67784
|
+
let toDecimals = await toToken.decimals();
|
|
67785
|
+
|
|
67786
|
+
return new PaymentRoute({
|
|
67787
|
+
blockchain,
|
|
67788
|
+
fromToken,
|
|
67789
|
+
fromAmount,
|
|
67790
|
+
fromDecimals,
|
|
67791
|
+
toToken,
|
|
67792
|
+
toDecimals,
|
|
67793
|
+
fromAddress: configuration.fromAddress,
|
|
67794
|
+
toAddress: configuration.toAddress,
|
|
67795
|
+
toContract: configuration.toContract
|
|
67796
|
+
})
|
|
67797
|
+
}
|
|
67771
67798
|
}))
|
|
67772
|
-
})).then((routes)=> routes.flat())
|
|
67799
|
+
})).then((routes)=> routes.flat().filter(el => el))
|
|
67773
67800
|
}
|
|
67774
67801
|
|
|
67775
67802
|
async function route({ accept, whitelist, blacklist, apiKey, event, fee }) {
|
|
@@ -67786,7 +67813,7 @@
|
|
|
67786
67813
|
.then(addApproval)
|
|
67787
67814
|
.then(sortPaymentRoutes)
|
|
67788
67815
|
.then((routes)=>addTransactions({ routes, event, fee }))
|
|
67789
|
-
.then(
|
|
67816
|
+
.then(addRouteAmounts)
|
|
67790
67817
|
.then(filterDuplicateFromTokens);
|
|
67791
67818
|
|
|
67792
67819
|
return paymentRoutes
|
|
@@ -67825,14 +67852,25 @@
|
|
|
67825
67852
|
return await Promise.all(
|
|
67826
67853
|
routes.map((route) => {
|
|
67827
67854
|
if(route.directTransfer) { return [] }
|
|
67828
|
-
|
|
67829
|
-
|
|
67830
|
-
|
|
67831
|
-
|
|
67832
|
-
|
|
67833
|
-
|
|
67834
|
-
|
|
67835
|
-
|
|
67855
|
+
if(route.toToken && route.toAmount) {
|
|
67856
|
+
return route$8({
|
|
67857
|
+
blockchain: route.blockchain,
|
|
67858
|
+
tokenIn: route.fromToken.address,
|
|
67859
|
+
tokenOut: route.toToken.address,
|
|
67860
|
+
amountOutMin: route.toAmount,
|
|
67861
|
+
fromAddress: route.fromAddress,
|
|
67862
|
+
toAddress: route.toAddress
|
|
67863
|
+
})
|
|
67864
|
+
} else if(route.fromToken && route.fromAmount) {
|
|
67865
|
+
return route$8({
|
|
67866
|
+
blockchain: route.blockchain,
|
|
67867
|
+
tokenIn: route.fromToken.address,
|
|
67868
|
+
tokenOut: route.toToken.address,
|
|
67869
|
+
amountIn: route.fromAmount,
|
|
67870
|
+
fromAddress: route.fromAddress,
|
|
67871
|
+
toAddress: route.toAddress
|
|
67872
|
+
})
|
|
67873
|
+
}
|
|
67836
67874
|
}),
|
|
67837
67875
|
).then((exchangeRoutes) => {
|
|
67838
67876
|
return routes.map((route, index) => {
|
|
@@ -67862,8 +67900,10 @@
|
|
|
67862
67900
|
return routes.filter((route) => {
|
|
67863
67901
|
if (route.fromToken.address.toLowerCase() == route.toToken.address.toLowerCase()) {
|
|
67864
67902
|
return BigNumber.from(route.fromBalance).gte(BigNumber.from(route.toAmount))
|
|
67865
|
-
} else {
|
|
67903
|
+
} else if(route.fromAmount && route.toAmount) {
|
|
67866
67904
|
return BigNumber.from(route.fromBalance).gte(BigNumber.from(route.exchangeRoutes[0].amountInMax))
|
|
67905
|
+
} else if(route.exchangeRoutes[0] && route.exchangeRoutes[0].amountIn) {
|
|
67906
|
+
return BigNumber.from(route.fromBalance).gte(BigNumber.from(route.exchangeRoutes[0].amountIn))
|
|
67867
67907
|
}
|
|
67868
67908
|
})
|
|
67869
67909
|
};
|
|
@@ -67906,16 +67946,19 @@
|
|
|
67906
67946
|
})
|
|
67907
67947
|
};
|
|
67908
67948
|
|
|
67909
|
-
let
|
|
67949
|
+
let addRouteAmounts = (routes)=> {
|
|
67910
67950
|
return routes.map((route)=>{
|
|
67911
67951
|
if(route.directTransfer && !route.fee) {
|
|
67912
67952
|
if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
|
|
67913
67953
|
route.fromAmount = route.transaction.value;
|
|
67954
|
+
route.toAmount = route.transaction.value;
|
|
67914
67955
|
} else {
|
|
67915
67956
|
route.fromAmount = route.transaction.params[1];
|
|
67957
|
+
route.toAmount = route.transaction.params[1];
|
|
67916
67958
|
}
|
|
67917
67959
|
} else {
|
|
67918
67960
|
route.fromAmount = route.transaction.params.amounts[0];
|
|
67961
|
+
route.toAmount = route.transaction.params.amounts[1];
|
|
67919
67962
|
}
|
|
67920
67963
|
return route
|
|
67921
67964
|
})
|
|
@@ -68186,15 +68229,20 @@
|
|
|
68186
68229
|
paymentValue = _useState2[0],
|
|
68187
68230
|
setPaymentValue = _useState2[1];
|
|
68188
68231
|
|
|
68232
|
+
var _useState3 = react.useState(),
|
|
68233
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
68234
|
+
paymentValueLoss = _useState4[0],
|
|
68235
|
+
setPaymentValueLoss = _useState4[1];
|
|
68236
|
+
|
|
68189
68237
|
var _useContext5 = react.useContext(ConfigurationContext),
|
|
68190
68238
|
currency = _useContext5.currency;
|
|
68191
68239
|
|
|
68192
|
-
var
|
|
68193
|
-
|
|
68194
|
-
reloadCount =
|
|
68195
|
-
setReloadCount =
|
|
68240
|
+
var _useState5 = react.useState(0),
|
|
68241
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
68242
|
+
reloadCount = _useState6[0],
|
|
68243
|
+
setReloadCount = _useState6[1];
|
|
68196
68244
|
|
|
68197
|
-
var
|
|
68245
|
+
var updatePaymentValue = function updatePaymentValue(_ref) {
|
|
68198
68246
|
var updatable = _ref.updatable,
|
|
68199
68247
|
payment = _ref.payment;
|
|
68200
68248
|
|
|
@@ -68209,29 +68257,51 @@
|
|
|
68209
68257
|
amountIn: payment.route.toAmount,
|
|
68210
68258
|
fromAddress: account,
|
|
68211
68259
|
toAddress: account
|
|
68212
|
-
}),
|
|
68260
|
+
}), !payment.route.directTransfer ? route$8({
|
|
68261
|
+
blockchain: payment.route.blockchain,
|
|
68262
|
+
tokenIn: payment.route.toToken.address,
|
|
68263
|
+
tokenOut: payment.route.fromToken.address,
|
|
68264
|
+
amountIn: payment.route.toAmount,
|
|
68265
|
+
fromAddress: account,
|
|
68266
|
+
toAddress: account
|
|
68267
|
+
}) : Promise.resolve([]), new Token({
|
|
68213
68268
|
blockchain: payment.route.blockchain,
|
|
68214
68269
|
address: CONSTANTS$2[payment.route.blockchain].USD
|
|
68215
68270
|
}).decimals()]).then(function (_ref2) {
|
|
68216
|
-
var _ref3 = _slicedToArray(_ref2,
|
|
68217
|
-
|
|
68218
|
-
|
|
68271
|
+
var _ref3 = _slicedToArray(_ref2, 3),
|
|
68272
|
+
toTokenUSDExchangeRoutes = _ref3[0],
|
|
68273
|
+
reverseRoutes = _ref3[1],
|
|
68274
|
+
USDDecimals = _ref3[2];
|
|
68275
|
+
|
|
68276
|
+
var toTokenUSDRoute = toTokenUSDExchangeRoutes[0];
|
|
68277
|
+
var reverseRoute = reverseRoutes[0];
|
|
68219
68278
|
|
|
68220
|
-
|
|
68221
|
-
|
|
68279
|
+
if (reverseRoute) {
|
|
68280
|
+
var reverseAmountOutBN = BigNumber$4.from(reverseRoute.amountOut);
|
|
68281
|
+
var paymentAmountInBN = BigNumber$4.from(payment.route.fromAmount);
|
|
68282
|
+
var divPercent = 100 - reverseAmountOutBN.mul(BigNumber$4.from('100')).div(paymentAmountInBN).abs().toString();
|
|
68283
|
+
|
|
68284
|
+
if (divPercent >= 5) {
|
|
68285
|
+
setPaymentValueLoss(divPercent);
|
|
68286
|
+
} else {
|
|
68287
|
+
setPaymentValueLoss(null);
|
|
68288
|
+
}
|
|
68289
|
+
}
|
|
68290
|
+
|
|
68291
|
+
var toTokenUSDAmount;
|
|
68222
68292
|
|
|
68223
68293
|
if (payment.route.toToken.address.toLowerCase() == CONSTANTS$2[payment.route.blockchain].USD.toLowerCase()) {
|
|
68224
|
-
|
|
68225
|
-
} else if (
|
|
68294
|
+
toTokenUSDAmount = payment.route.toAmount.toString();
|
|
68295
|
+
} else if (toTokenUSDRoute == undefined) {
|
|
68226
68296
|
setPaymentValue('');
|
|
68227
68297
|
return;
|
|
68228
68298
|
} else {
|
|
68229
|
-
|
|
68299
|
+
toTokenUSDAmount = toTokenUSDRoute.amountOut.toString();
|
|
68230
68300
|
}
|
|
68231
68301
|
|
|
68232
|
-
var
|
|
68302
|
+
var toTokenUSDValue = formatUnits(toTokenUSDAmount, USDDecimals);
|
|
68233
68303
|
Currency.fromUSD({
|
|
68234
|
-
amount:
|
|
68304
|
+
amount: toTokenUSDValue,
|
|
68235
68305
|
code: currency,
|
|
68236
68306
|
apiKey: apiKey
|
|
68237
68307
|
}).then(setPaymentValue)["catch"](setError);
|
|
@@ -68240,7 +68310,7 @@
|
|
|
68240
68310
|
|
|
68241
68311
|
react.useEffect(function () {
|
|
68242
68312
|
if (account && payment) {
|
|
68243
|
-
|
|
68313
|
+
updatePaymentValue({
|
|
68244
68314
|
updatable: updatable,
|
|
68245
68315
|
payment: payment
|
|
68246
68316
|
});
|
|
@@ -68249,7 +68319,7 @@
|
|
|
68249
68319
|
react.useEffect(function () {
|
|
68250
68320
|
var timeout = setTimeout(function () {
|
|
68251
68321
|
setReloadCount(reloadCount + 1);
|
|
68252
|
-
|
|
68322
|
+
updatePaymentValue({
|
|
68253
68323
|
updatable: updatable
|
|
68254
68324
|
});
|
|
68255
68325
|
}, 15000);
|
|
@@ -68259,7 +68329,8 @@
|
|
|
68259
68329
|
}, [reloadCount, updatable]);
|
|
68260
68330
|
return /*#__PURE__*/react.createElement(PaymentValueContext.Provider, {
|
|
68261
68331
|
value: {
|
|
68262
|
-
paymentValue: paymentValue
|
|
68332
|
+
paymentValue: paymentValue,
|
|
68333
|
+
paymentValueLoss: paymentValueLoss
|
|
68263
68334
|
}
|
|
68264
68335
|
}, props.children);
|
|
68265
68336
|
});
|
|
@@ -70407,7 +70478,8 @@
|
|
|
70407
70478
|
approvalTransaction = _useContext4.approvalTransaction;
|
|
70408
70479
|
|
|
70409
70480
|
var _useContext5 = react.useContext(PaymentValueContext),
|
|
70410
|
-
paymentValue = _useContext5.paymentValue
|
|
70481
|
+
paymentValue = _useContext5.paymentValue,
|
|
70482
|
+
paymentValueLoss = _useContext5.paymentValueLoss;
|
|
70411
70483
|
|
|
70412
70484
|
var _useContext6 = react.useContext(NavigateStackContext);
|
|
70413
70485
|
_useContext6.navigate;
|
|
@@ -70553,7 +70625,16 @@
|
|
|
70553
70625
|
displayedAmount = "".concat(payment.symbol, " ").concat(payment.amount);
|
|
70554
70626
|
}
|
|
70555
70627
|
|
|
70556
|
-
if (
|
|
70628
|
+
if (paymentValueLoss) {
|
|
70629
|
+
return /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement("div", {
|
|
70630
|
+
className: "PaddingBottomXS"
|
|
70631
|
+
}, /*#__PURE__*/react.createElement("div", {
|
|
70632
|
+
className: "Alert"
|
|
70633
|
+
}, /*#__PURE__*/react.createElement("strong", null, "Payment token would lose ", paymentValueLoss, "% of it's value!"))), /*#__PURE__*/react.createElement("button", {
|
|
70634
|
+
className: "ButtonPrimary disabled",
|
|
70635
|
+
onClick: function onClick() {}
|
|
70636
|
+
}, "Pay ", displayedAmount));
|
|
70637
|
+
} else if ((paymentState == 'initialized' || paymentState == 'approving') && payment.route) {
|
|
70557
70638
|
return /*#__PURE__*/react.createElement("button", {
|
|
70558
70639
|
className: ["ButtonPrimary", payment.route.approvalRequired && !payment.route.directTransfer ? 'disabled' : ''].join(' '),
|
|
70559
70640
|
onClick: function onClick() {
|
|
@@ -70851,11 +70932,11 @@
|
|
|
70851
70932
|
paymentRoute = _useState6[0],
|
|
70852
70933
|
setPaymentRoute = _useState6[1];
|
|
70853
70934
|
|
|
70854
|
-
var _useState7 = react.useState(track &&
|
|
70935
|
+
var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
|
|
70855
70936
|
_useState8 = _slicedToArray(_useState7, 1),
|
|
70856
70937
|
tracking = _useState8[0];
|
|
70857
70938
|
|
|
70858
|
-
var _useState9 = react.useState(track && track.poll &&
|
|
70939
|
+
var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
|
|
70859
70940
|
_useState10 = _slicedToArray(_useState9, 1),
|
|
70860
70941
|
polling = _useState10[0];
|
|
70861
70942
|
|
|
@@ -70923,7 +71004,6 @@
|
|
|
70923
71004
|
|
|
70924
71005
|
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70925
71006
|
attempt = parseInt(attempt || 1, 10);
|
|
70926
|
-
console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
|
|
70927
71007
|
|
|
70928
71008
|
if (attempt < 3) {
|
|
70929
71009
|
setTimeout(function () {
|
|
@@ -70966,9 +71046,7 @@
|
|
|
70966
71046
|
after_block: afterBlock,
|
|
70967
71047
|
to_token: paymentRoute.toToken.address
|
|
70968
71048
|
}).then(function (response) {
|
|
70969
|
-
if (response.status
|
|
70970
|
-
console.log('PAYMENT TRACKING INITIALIZED');
|
|
70971
|
-
} else {
|
|
71049
|
+
if (response.status != 200) {
|
|
70972
71050
|
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
70973
71051
|
}
|
|
70974
71052
|
})["catch"](function (error) {
|
|
@@ -71032,7 +71110,56 @@
|
|
|
71032
71110
|
};
|
|
71033
71111
|
}, [polling, transaction, afterBlock, paymentRoute]);
|
|
71034
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
|
+
|
|
71035
71156
|
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
71157
|
+
storePayment(transaction, afterBlock, paymentRoute, 1);
|
|
71158
|
+
|
|
71159
|
+
if (tracking == false) {
|
|
71160
|
+
return;
|
|
71161
|
+
}
|
|
71162
|
+
|
|
71036
71163
|
setTransaction(transaction);
|
|
71037
71164
|
setAfterBlock(afterBlock);
|
|
71038
71165
|
setPaymentRoute(paymentRoute);
|
|
@@ -71200,8 +71327,11 @@
|
|
|
71200
71327
|
});
|
|
71201
71328
|
|
|
71202
71329
|
var WalletProvider = (function (props) {
|
|
71203
|
-
var _useContext = react.useContext(
|
|
71204
|
-
_useContext.
|
|
71330
|
+
var _useContext = react.useContext(ConfigurationContext),
|
|
71331
|
+
recover = _useContext.recover;
|
|
71332
|
+
|
|
71333
|
+
var _useContext2 = react.useContext(ErrorContext);
|
|
71334
|
+
_useContext2.setError;
|
|
71205
71335
|
|
|
71206
71336
|
var _useState = react.useState(),
|
|
71207
71337
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -71230,7 +71360,7 @@
|
|
|
71230
71360
|
}
|
|
71231
71361
|
};
|
|
71232
71362
|
|
|
71233
|
-
if (walletState == 'connected') {
|
|
71363
|
+
if (walletState == 'connected' || recover != undefined) {
|
|
71234
71364
|
return /*#__PURE__*/react.createElement(WalletContext.Provider, {
|
|
71235
71365
|
value: {
|
|
71236
71366
|
account: account,
|
|
@@ -71762,10 +71892,14 @@
|
|
|
71762
71892
|
throw 'You need to set a supported blockchain!';
|
|
71763
71893
|
}
|
|
71764
71894
|
|
|
71765
|
-
if (typeof configuration.token === 'undefined') {
|
|
71895
|
+
if (typeof configuration.token === 'undefined' && typeof configuration.fromToken === 'undefined' && typeof configuration.fromAmount === 'undefined' && typeof configuration.toToken === 'undefined') {
|
|
71766
71896
|
throw 'You need to set the token you want to receive as payment!';
|
|
71767
71897
|
}
|
|
71768
71898
|
|
|
71899
|
+
if (typeof configuration.token === 'undefined' && typeof configuration.fromToken !== 'undefined' && typeof configuration.fromAmount === 'undefined' && typeof configuration.toToken === 'undefined') {
|
|
71900
|
+
throw 'You need to set the fromToken, fromAmount and toToken!';
|
|
71901
|
+
}
|
|
71902
|
+
|
|
71769
71903
|
if (typeof configuration.receiver === 'undefined') {
|
|
71770
71904
|
throw 'You need to set the receiver address that you want to receive the payment!';
|
|
71771
71905
|
}
|