@depay/widgets 6.13.1 → 6.16.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/README.md +19 -0
- package/dist/esm/index.bundle.js +207 -76
- package/dist/esm/index.js +122 -36
- package/dist/umd/index.bundle.js +207 -76
- package/dist/umd/index.js +122 -36
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -194,6 +194,25 @@ DePayWidgets.Payment({
|
|
|
194
194
|
});
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
+
#### fromToken, fromAmount + toToken
|
|
198
|
+
|
|
199
|
+
In case where you want to configure payments based on the source token + amount, rather than target token and amount, you can pass `fromToken`, `fromAmount` and `toToken` to `accept`.
|
|
200
|
+
|
|
201
|
+
In those cases make sure to NOT configure `token` nor `amount`!
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
DePayWidgets.Payment({
|
|
205
|
+
accept: [{
|
|
206
|
+
blockchain: 'bsc',
|
|
207
|
+
fromToken: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
|
|
208
|
+
fromAmount: 0.1,
|
|
209
|
+
toToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
|
|
210
|
+
receiver: '0x08B277154218CCF3380CAE48d630DA13462E3950'
|
|
211
|
+
}]
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// This will open a payment widget to send 0.1 BUSD to the receiver, converting it to BNB along the way.
|
|
215
|
+
```
|
|
197
216
|
|
|
198
217
|
#### track
|
|
199
218
|
|
package/dist/esm/index.bundle.js
CHANGED
|
@@ -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
|
-
|
|
55319
|
-
|
|
55320
|
-
|
|
55321
|
-
|
|
55322
|
-
|
|
55323
|
-
|
|
55324
|
-
|
|
55325
|
-
|
|
55326
|
-
|
|
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() {
|
|
@@ -61718,13 +61722,14 @@ let route$8 = ({
|
|
|
61718
61722
|
var ChangableAmountProvider = (function (props) {
|
|
61719
61723
|
var configurationsMissAmounts = function configurationsMissAmounts(configurations) {
|
|
61720
61724
|
return !configurations.every(function (configuration) {
|
|
61721
|
-
return typeof configuration.amount != 'undefined';
|
|
61725
|
+
return typeof configuration.amount != 'undefined' || typeof configuration.fromAmount != 'undefined';
|
|
61722
61726
|
});
|
|
61723
61727
|
};
|
|
61724
61728
|
|
|
61725
61729
|
var _useContext = react.useContext(ConfigurationContext),
|
|
61726
|
-
amountConfiguration = _useContext.amount
|
|
61727
|
-
|
|
61730
|
+
amountConfiguration = _useContext.amount;
|
|
61731
|
+
_useContext.toAmount;
|
|
61732
|
+
var recover = _useContext.recover;
|
|
61728
61733
|
|
|
61729
61734
|
var _useState = react.useState(recover == undefined ? configurationsMissAmounts(props.accept) : false),
|
|
61730
61735
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -62470,7 +62475,7 @@ var PaymentProvider = (function (props) {
|
|
|
62470
62475
|
var _useContext9 = react.useContext(PaymentTrackingContext),
|
|
62471
62476
|
release = _useContext9.release,
|
|
62472
62477
|
tracking = _useContext9.tracking,
|
|
62473
|
-
|
|
62478
|
+
initializePaymentTracking = _useContext9.initializeTracking;
|
|
62474
62479
|
|
|
62475
62480
|
var _useContext10 = react.useContext(TransactionTrackingContext),
|
|
62476
62481
|
foundTransaction = _useContext10.foundTransaction,
|
|
@@ -62550,10 +62555,7 @@ var PaymentProvider = (function (props) {
|
|
|
62550
62555
|
confirmed: paymentConfirmed,
|
|
62551
62556
|
failed: paymentFailed
|
|
62552
62557
|
})).then(function (sentTransaction) {
|
|
62553
|
-
|
|
62554
|
-
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
62555
|
-
}
|
|
62556
|
-
|
|
62558
|
+
initializePaymentTracking(sentTransaction, currentBlock, payment.route);
|
|
62557
62559
|
setTransaction(sentTransaction);
|
|
62558
62560
|
})["catch"](function (error) {
|
|
62559
62561
|
console.log('error', error);
|
|
@@ -67681,14 +67683,16 @@ let transactionValue = ({ paymentRoute, exchangeRoute })=> {
|
|
|
67681
67683
|
|
|
67682
67684
|
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; }
|
|
67683
67685
|
class PaymentRoute {
|
|
67684
|
-
constructor({ blockchain, fromToken, toToken, toDecimals, toAmount,
|
|
67686
|
+
constructor({ blockchain, fromAddress, fromToken, fromDecimals, fromAmount, toToken, toDecimals, toAmount, toAddress, toContract }) {
|
|
67685
67687
|
this.blockchain = blockchain;
|
|
67688
|
+
this.fromAddress = fromAddress;
|
|
67686
67689
|
this.fromToken = fromToken;
|
|
67690
|
+
this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
|
|
67691
|
+
this.fromDecimals = fromDecimals;
|
|
67687
67692
|
this.fromBalance = 0;
|
|
67688
67693
|
this.toToken = toToken;
|
|
67694
|
+
this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
67689
67695
|
this.toDecimals = toDecimals;
|
|
67690
|
-
this.toAmount = _optionalChain([toAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
|
|
67691
|
-
this.fromAddress = fromAddress;
|
|
67692
67696
|
this.toAddress = toAddress;
|
|
67693
67697
|
this.toContract = toContract;
|
|
67694
67698
|
this.exchangeRoutes = [];
|
|
@@ -67748,22 +67752,45 @@ function convertToRoutes({ tokens, accept }) {
|
|
|
67748
67752
|
return Promise.all(tokens.map(async (fromToken)=>{
|
|
67749
67753
|
let relevantConfigurations = accept.filter((configuration)=>(configuration.blockchain == fromToken.blockchain));
|
|
67750
67754
|
return Promise.all(relevantConfigurations.map(async (configuration)=>{
|
|
67751
|
-
|
|
67752
|
-
|
|
67753
|
-
|
|
67754
|
-
|
|
67755
|
-
|
|
67756
|
-
|
|
67757
|
-
|
|
67758
|
-
|
|
67759
|
-
|
|
67760
|
-
|
|
67761
|
-
|
|
67762
|
-
|
|
67763
|
-
|
|
67764
|
-
|
|
67755
|
+
if(configuration.token && configuration.amount) {
|
|
67756
|
+
let blockchain = configuration.blockchain;
|
|
67757
|
+
let toToken = new Token({ blockchain, address: configuration.token });
|
|
67758
|
+
let fromDecimals = await fromToken.decimals();
|
|
67759
|
+
let toDecimals = await toToken.decimals();
|
|
67760
|
+
let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
|
|
67761
|
+
|
|
67762
|
+
return new PaymentRoute({
|
|
67763
|
+
blockchain,
|
|
67764
|
+
fromToken,
|
|
67765
|
+
fromDecimals,
|
|
67766
|
+
toToken,
|
|
67767
|
+
toAmount,
|
|
67768
|
+
toDecimals,
|
|
67769
|
+
fromAddress: configuration.fromAddress,
|
|
67770
|
+
toAddress: configuration.toAddress,
|
|
67771
|
+
toContract: configuration.toContract
|
|
67772
|
+
})
|
|
67773
|
+
} else if(configuration.fromToken && configuration.fromAmount && fromToken.address.toLowerCase() == configuration.fromToken.toLowerCase()) {
|
|
67774
|
+
let blockchain = configuration.blockchain;
|
|
67775
|
+
let fromAmount = (await fromToken.BigNumber(configuration.fromAmount)).toString();
|
|
67776
|
+
let fromDecimals = await fromToken.decimals();
|
|
67777
|
+
let toToken = new Token({ blockchain, address: configuration.toToken });
|
|
67778
|
+
let toDecimals = await toToken.decimals();
|
|
67779
|
+
|
|
67780
|
+
return new PaymentRoute({
|
|
67781
|
+
blockchain,
|
|
67782
|
+
fromToken,
|
|
67783
|
+
fromAmount,
|
|
67784
|
+
fromDecimals,
|
|
67785
|
+
toToken,
|
|
67786
|
+
toDecimals,
|
|
67787
|
+
fromAddress: configuration.fromAddress,
|
|
67788
|
+
toAddress: configuration.toAddress,
|
|
67789
|
+
toContract: configuration.toContract
|
|
67790
|
+
})
|
|
67791
|
+
}
|
|
67765
67792
|
}))
|
|
67766
|
-
})).then((routes)=> routes.flat())
|
|
67793
|
+
})).then((routes)=> routes.flat().filter(el => el))
|
|
67767
67794
|
}
|
|
67768
67795
|
|
|
67769
67796
|
async function route({ accept, whitelist, blacklist, apiKey, event, fee }) {
|
|
@@ -67780,7 +67807,7 @@ async function route({ accept, whitelist, blacklist, apiKey, event, fee }) {
|
|
|
67780
67807
|
.then(addApproval)
|
|
67781
67808
|
.then(sortPaymentRoutes)
|
|
67782
67809
|
.then((routes)=>addTransactions({ routes, event, fee }))
|
|
67783
|
-
.then(
|
|
67810
|
+
.then(addRouteAmounts)
|
|
67784
67811
|
.then(filterDuplicateFromTokens);
|
|
67785
67812
|
|
|
67786
67813
|
return paymentRoutes
|
|
@@ -67819,14 +67846,25 @@ let addExchangeRoutes = async (routes) => {
|
|
|
67819
67846
|
return await Promise.all(
|
|
67820
67847
|
routes.map((route) => {
|
|
67821
67848
|
if(route.directTransfer) { return [] }
|
|
67822
|
-
|
|
67823
|
-
|
|
67824
|
-
|
|
67825
|
-
|
|
67826
|
-
|
|
67827
|
-
|
|
67828
|
-
|
|
67829
|
-
|
|
67849
|
+
if(route.toToken && route.toAmount) {
|
|
67850
|
+
return route$8({
|
|
67851
|
+
blockchain: route.blockchain,
|
|
67852
|
+
tokenIn: route.fromToken.address,
|
|
67853
|
+
tokenOut: route.toToken.address,
|
|
67854
|
+
amountOutMin: route.toAmount,
|
|
67855
|
+
fromAddress: route.fromAddress,
|
|
67856
|
+
toAddress: route.toAddress
|
|
67857
|
+
})
|
|
67858
|
+
} else if(route.fromToken && route.fromAmount) {
|
|
67859
|
+
return route$8({
|
|
67860
|
+
blockchain: route.blockchain,
|
|
67861
|
+
tokenIn: route.fromToken.address,
|
|
67862
|
+
tokenOut: route.toToken.address,
|
|
67863
|
+
amountIn: route.fromAmount,
|
|
67864
|
+
fromAddress: route.fromAddress,
|
|
67865
|
+
toAddress: route.toAddress
|
|
67866
|
+
})
|
|
67867
|
+
}
|
|
67830
67868
|
}),
|
|
67831
67869
|
).then((exchangeRoutes) => {
|
|
67832
67870
|
return routes.map((route, index) => {
|
|
@@ -67856,8 +67894,10 @@ let filterInsufficientBalance = async(routes) => {
|
|
|
67856
67894
|
return routes.filter((route) => {
|
|
67857
67895
|
if (route.fromToken.address.toLowerCase() == route.toToken.address.toLowerCase()) {
|
|
67858
67896
|
return BigNumber.from(route.fromBalance).gte(BigNumber.from(route.toAmount))
|
|
67859
|
-
} else {
|
|
67897
|
+
} else if(route.fromAmount && route.toAmount) {
|
|
67860
67898
|
return BigNumber.from(route.fromBalance).gte(BigNumber.from(route.exchangeRoutes[0].amountInMax))
|
|
67899
|
+
} else if(route.exchangeRoutes[0] && route.exchangeRoutes[0].amountIn) {
|
|
67900
|
+
return BigNumber.from(route.fromBalance).gte(BigNumber.from(route.exchangeRoutes[0].amountIn))
|
|
67861
67901
|
}
|
|
67862
67902
|
})
|
|
67863
67903
|
};
|
|
@@ -67900,16 +67940,19 @@ let addDirectTransferStatus = (routes) => {
|
|
|
67900
67940
|
})
|
|
67901
67941
|
};
|
|
67902
67942
|
|
|
67903
|
-
let
|
|
67943
|
+
let addRouteAmounts = (routes)=> {
|
|
67904
67944
|
return routes.map((route)=>{
|
|
67905
67945
|
if(route.directTransfer && !route.fee) {
|
|
67906
67946
|
if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
|
|
67907
67947
|
route.fromAmount = route.transaction.value;
|
|
67948
|
+
route.toAmount = route.transaction.value;
|
|
67908
67949
|
} else {
|
|
67909
67950
|
route.fromAmount = route.transaction.params[1];
|
|
67951
|
+
route.toAmount = route.transaction.params[1];
|
|
67910
67952
|
}
|
|
67911
67953
|
} else {
|
|
67912
67954
|
route.fromAmount = route.transaction.params.amounts[0];
|
|
67955
|
+
route.toAmount = route.transaction.params.amounts[1];
|
|
67913
67956
|
}
|
|
67914
67957
|
return route
|
|
67915
67958
|
})
|
|
@@ -68180,15 +68223,20 @@ var PaymentValueProvider = (function (props) {
|
|
|
68180
68223
|
paymentValue = _useState2[0],
|
|
68181
68224
|
setPaymentValue = _useState2[1];
|
|
68182
68225
|
|
|
68226
|
+
var _useState3 = react.useState(),
|
|
68227
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
68228
|
+
paymentValueLoss = _useState4[0],
|
|
68229
|
+
setPaymentValueLoss = _useState4[1];
|
|
68230
|
+
|
|
68183
68231
|
var _useContext5 = react.useContext(ConfigurationContext),
|
|
68184
68232
|
currency = _useContext5.currency;
|
|
68185
68233
|
|
|
68186
|
-
var
|
|
68187
|
-
|
|
68188
|
-
reloadCount =
|
|
68189
|
-
setReloadCount =
|
|
68234
|
+
var _useState5 = react.useState(0),
|
|
68235
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
68236
|
+
reloadCount = _useState6[0],
|
|
68237
|
+
setReloadCount = _useState6[1];
|
|
68190
68238
|
|
|
68191
|
-
var
|
|
68239
|
+
var updatePaymentValue = function updatePaymentValue(_ref) {
|
|
68192
68240
|
var updatable = _ref.updatable,
|
|
68193
68241
|
payment = _ref.payment;
|
|
68194
68242
|
|
|
@@ -68203,29 +68251,51 @@ var PaymentValueProvider = (function (props) {
|
|
|
68203
68251
|
amountIn: payment.route.toAmount,
|
|
68204
68252
|
fromAddress: account,
|
|
68205
68253
|
toAddress: account
|
|
68206
|
-
}),
|
|
68254
|
+
}), !payment.route.directTransfer ? route$8({
|
|
68255
|
+
blockchain: payment.route.blockchain,
|
|
68256
|
+
tokenIn: payment.route.toToken.address,
|
|
68257
|
+
tokenOut: payment.route.fromToken.address,
|
|
68258
|
+
amountIn: payment.route.toAmount,
|
|
68259
|
+
fromAddress: account,
|
|
68260
|
+
toAddress: account
|
|
68261
|
+
}) : Promise.resolve([]), new Token({
|
|
68207
68262
|
blockchain: payment.route.blockchain,
|
|
68208
68263
|
address: CONSTANTS$2[payment.route.blockchain].USD
|
|
68209
68264
|
}).decimals()]).then(function (_ref2) {
|
|
68210
|
-
var _ref3 = _slicedToArray(_ref2,
|
|
68211
|
-
|
|
68212
|
-
|
|
68265
|
+
var _ref3 = _slicedToArray(_ref2, 3),
|
|
68266
|
+
toTokenUSDExchangeRoutes = _ref3[0],
|
|
68267
|
+
reverseRoutes = _ref3[1],
|
|
68268
|
+
USDDecimals = _ref3[2];
|
|
68269
|
+
|
|
68270
|
+
var toTokenUSDRoute = toTokenUSDExchangeRoutes[0];
|
|
68271
|
+
var reverseRoute = reverseRoutes[0];
|
|
68213
68272
|
|
|
68214
|
-
|
|
68215
|
-
|
|
68273
|
+
if (reverseRoute) {
|
|
68274
|
+
var reverseAmountOutBN = BigNumber$4.from(reverseRoute.amountOut);
|
|
68275
|
+
var paymentAmountInBN = BigNumber$4.from(payment.route.fromAmount);
|
|
68276
|
+
var divPercent = 100 - reverseAmountOutBN.mul(BigNumber$4.from('100')).div(paymentAmountInBN).abs().toString();
|
|
68277
|
+
|
|
68278
|
+
if (divPercent > 5) {
|
|
68279
|
+
setPaymentValueLoss(divPercent);
|
|
68280
|
+
} else {
|
|
68281
|
+
setPaymentValueLoss(null);
|
|
68282
|
+
}
|
|
68283
|
+
}
|
|
68284
|
+
|
|
68285
|
+
var toTokenUSDAmount;
|
|
68216
68286
|
|
|
68217
68287
|
if (payment.route.toToken.address.toLowerCase() == CONSTANTS$2[payment.route.blockchain].USD.toLowerCase()) {
|
|
68218
|
-
|
|
68219
|
-
} else if (
|
|
68288
|
+
toTokenUSDAmount = payment.route.toAmount.toString();
|
|
68289
|
+
} else if (toTokenUSDRoute == undefined) {
|
|
68220
68290
|
setPaymentValue('');
|
|
68221
68291
|
return;
|
|
68222
68292
|
} else {
|
|
68223
|
-
|
|
68293
|
+
toTokenUSDAmount = toTokenUSDRoute.amountOut.toString();
|
|
68224
68294
|
}
|
|
68225
68295
|
|
|
68226
|
-
var
|
|
68296
|
+
var toTokenUSDValue = formatUnits(toTokenUSDAmount, USDDecimals);
|
|
68227
68297
|
Currency.fromUSD({
|
|
68228
|
-
amount:
|
|
68298
|
+
amount: toTokenUSDValue,
|
|
68229
68299
|
code: currency,
|
|
68230
68300
|
apiKey: apiKey
|
|
68231
68301
|
}).then(setPaymentValue)["catch"](setError);
|
|
@@ -68234,7 +68304,7 @@ var PaymentValueProvider = (function (props) {
|
|
|
68234
68304
|
|
|
68235
68305
|
react.useEffect(function () {
|
|
68236
68306
|
if (account && payment) {
|
|
68237
|
-
|
|
68307
|
+
updatePaymentValue({
|
|
68238
68308
|
updatable: updatable,
|
|
68239
68309
|
payment: payment
|
|
68240
68310
|
});
|
|
@@ -68243,7 +68313,7 @@ var PaymentValueProvider = (function (props) {
|
|
|
68243
68313
|
react.useEffect(function () {
|
|
68244
68314
|
var timeout = setTimeout(function () {
|
|
68245
68315
|
setReloadCount(reloadCount + 1);
|
|
68246
|
-
|
|
68316
|
+
updatePaymentValue({
|
|
68247
68317
|
updatable: updatable
|
|
68248
68318
|
});
|
|
68249
68319
|
}, 15000);
|
|
@@ -68253,7 +68323,8 @@ var PaymentValueProvider = (function (props) {
|
|
|
68253
68323
|
}, [reloadCount, updatable]);
|
|
68254
68324
|
return /*#__PURE__*/react.createElement(PaymentValueContext.Provider, {
|
|
68255
68325
|
value: {
|
|
68256
|
-
paymentValue: paymentValue
|
|
68326
|
+
paymentValue: paymentValue,
|
|
68327
|
+
paymentValueLoss: paymentValueLoss
|
|
68257
68328
|
}
|
|
68258
68329
|
}, props.children);
|
|
68259
68330
|
});
|
|
@@ -70401,7 +70472,8 @@ var Footer = (function () {
|
|
|
70401
70472
|
approvalTransaction = _useContext4.approvalTransaction;
|
|
70402
70473
|
|
|
70403
70474
|
var _useContext5 = react.useContext(PaymentValueContext),
|
|
70404
|
-
paymentValue = _useContext5.paymentValue
|
|
70475
|
+
paymentValue = _useContext5.paymentValue,
|
|
70476
|
+
paymentValueLoss = _useContext5.paymentValueLoss;
|
|
70405
70477
|
|
|
70406
70478
|
var _useContext6 = react.useContext(NavigateStackContext);
|
|
70407
70479
|
_useContext6.navigate;
|
|
@@ -70547,7 +70619,16 @@ var Footer = (function () {
|
|
|
70547
70619
|
displayedAmount = "".concat(payment.symbol, " ").concat(payment.amount);
|
|
70548
70620
|
}
|
|
70549
70621
|
|
|
70550
|
-
if (
|
|
70622
|
+
if (paymentValueLoss) {
|
|
70623
|
+
return /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement("div", {
|
|
70624
|
+
className: "PaddingBottomXS"
|
|
70625
|
+
}, /*#__PURE__*/react.createElement("div", {
|
|
70626
|
+
className: "Alert"
|
|
70627
|
+
}, /*#__PURE__*/react.createElement("strong", null, "Payment token would lose ", paymentValueLoss, "% of it's value!"))), /*#__PURE__*/react.createElement("button", {
|
|
70628
|
+
className: "ButtonPrimary disabled",
|
|
70629
|
+
onClick: function onClick() {}
|
|
70630
|
+
}, "Pay ", displayedAmount));
|
|
70631
|
+
} else if ((paymentState == 'initialized' || paymentState == 'approving') && payment.route) {
|
|
70551
70632
|
return /*#__PURE__*/react.createElement("button", {
|
|
70552
70633
|
className: ["ButtonPrimary", payment.route.approvalRequired && !payment.route.directTransfer ? 'disabled' : ''].join(' '),
|
|
70553
70634
|
onClick: function onClick() {
|
|
@@ -70845,11 +70926,11 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
70845
70926
|
paymentRoute = _useState6[0],
|
|
70846
70927
|
setPaymentRoute = _useState6[1];
|
|
70847
70928
|
|
|
70848
|
-
var _useState7 = react.useState(track &&
|
|
70929
|
+
var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
|
|
70849
70930
|
_useState8 = _slicedToArray(_useState7, 1),
|
|
70850
70931
|
tracking = _useState8[0];
|
|
70851
70932
|
|
|
70852
|
-
var _useState9 = react.useState(track && track.poll &&
|
|
70933
|
+
var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
|
|
70853
70934
|
_useState10 = _slicedToArray(_useState9, 1),
|
|
70854
70935
|
polling = _useState10[0];
|
|
70855
70936
|
|
|
@@ -70917,7 +70998,6 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
70917
70998
|
|
|
70918
70999
|
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70919
71000
|
attempt = parseInt(attempt || 1, 10);
|
|
70920
|
-
console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
|
|
70921
71001
|
|
|
70922
71002
|
if (attempt < 3) {
|
|
70923
71003
|
setTimeout(function () {
|
|
@@ -70960,9 +71040,7 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
70960
71040
|
after_block: afterBlock,
|
|
70961
71041
|
to_token: paymentRoute.toToken.address
|
|
70962
71042
|
}).then(function (response) {
|
|
70963
|
-
if (response.status
|
|
70964
|
-
console.log('PAYMENT TRACKING INITIALIZED');
|
|
70965
|
-
} else {
|
|
71043
|
+
if (response.status != 200) {
|
|
70966
71044
|
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
70967
71045
|
}
|
|
70968
71046
|
})["catch"](function (error) {
|
|
@@ -71026,7 +71104,56 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
71026
71104
|
};
|
|
71027
71105
|
}, [polling, transaction, afterBlock, paymentRoute]);
|
|
71028
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
|
+
|
|
71029
71150
|
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
71151
|
+
storePayment(transaction, afterBlock, paymentRoute, 1);
|
|
71152
|
+
|
|
71153
|
+
if (tracking == false) {
|
|
71154
|
+
return;
|
|
71155
|
+
}
|
|
71156
|
+
|
|
71030
71157
|
setTransaction(transaction);
|
|
71031
71158
|
setAfterBlock(afterBlock);
|
|
71032
71159
|
setPaymentRoute(paymentRoute);
|
|
@@ -71759,10 +71886,14 @@ var preflight$1 = /*#__PURE__*/function () {
|
|
|
71759
71886
|
throw 'You need to set a supported blockchain!';
|
|
71760
71887
|
}
|
|
71761
71888
|
|
|
71762
|
-
if (typeof configuration.token === 'undefined') {
|
|
71889
|
+
if (typeof configuration.token === 'undefined' && typeof configuration.fromToken === 'undefined' && typeof configuration.fromAmount === 'undefined' && typeof configuration.toToken === 'undefined') {
|
|
71763
71890
|
throw 'You need to set the token you want to receive as payment!';
|
|
71764
71891
|
}
|
|
71765
71892
|
|
|
71893
|
+
if (typeof configuration.token === 'undefined' && typeof configuration.fromToken !== 'undefined' && typeof configuration.fromAmount === 'undefined' && typeof configuration.toToken === 'undefined') {
|
|
71894
|
+
throw 'You need to set the fromToken, fromAmount and toToken!';
|
|
71895
|
+
}
|
|
71896
|
+
|
|
71766
71897
|
if (typeof configuration.receiver === 'undefined') {
|
|
71767
71898
|
throw 'You need to set the receiver address that you want to receive the payment!';
|
|
71768
71899
|
}
|