@depay/widgets 6.14.0 → 6.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.bundle.js +145 -50
- package/dist/esm/index.js +113 -32
- package/dist/umd/index.bundle.js +145 -50
- package/dist/umd/index.js +113 -32
- package/package.json +5 -5
package/dist/esm/index.bundle.js
CHANGED
|
@@ -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 = {
|
|
@@ -49025,7 +49029,7 @@ const wallets = {
|
|
|
49025
49029
|
const instances = {};
|
|
49026
49030
|
|
|
49027
49031
|
const getWalletClass = function(){
|
|
49028
|
-
if(
|
|
49032
|
+
if(getConnectedInstance()) {
|
|
49029
49033
|
return wallets.WalletConnect
|
|
49030
49034
|
} else if (typeof window.ethereum === 'object' && window.ethereum.isMetaMask) {
|
|
49031
49035
|
return wallets.MetaMask
|
|
@@ -49040,8 +49044,8 @@ const getWallet = function () {
|
|
|
49040
49044
|
const walletClass = getWalletClass();
|
|
49041
49045
|
const existingInstance = instances[walletClass];
|
|
49042
49046
|
|
|
49043
|
-
if(
|
|
49044
|
-
return
|
|
49047
|
+
if(getConnectedInstance()) {
|
|
49048
|
+
return getConnectedInstance()
|
|
49045
49049
|
} else if(existingInstance) {
|
|
49046
49050
|
return existingInstance
|
|
49047
49051
|
} else if(walletClass) {
|
|
@@ -55315,17 +55319,21 @@ class Token {
|
|
|
55315
55319
|
if (this.address == CONSTANTS$2[this.blockchain].NATIVE) {
|
|
55316
55320
|
return CONSTANTS$2[this.blockchain].DECIMALS
|
|
55317
55321
|
}
|
|
55318
|
-
|
|
55319
|
-
|
|
55320
|
-
|
|
55321
|
-
|
|
55322
|
-
|
|
55323
|
-
|
|
55324
|
-
|
|
55325
|
-
|
|
55326
|
-
|
|
55327
|
-
|
|
55328
|
-
|
|
55322
|
+
let decimals = 0;
|
|
55323
|
+
try {
|
|
55324
|
+
decimals = 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
|
+
);
|
|
55335
|
+
} catch (e) {}
|
|
55336
|
+
return decimals
|
|
55329
55337
|
}
|
|
55330
55338
|
|
|
55331
55339
|
async symbol() {
|
|
@@ -62471,7 +62479,7 @@ var PaymentProvider = (function (props) {
|
|
|
62471
62479
|
var _useContext9 = react.useContext(PaymentTrackingContext),
|
|
62472
62480
|
release = _useContext9.release,
|
|
62473
62481
|
tracking = _useContext9.tracking,
|
|
62474
|
-
|
|
62482
|
+
initializePaymentTracking = _useContext9.initializeTracking;
|
|
62475
62483
|
|
|
62476
62484
|
var _useContext10 = react.useContext(TransactionTrackingContext),
|
|
62477
62485
|
foundTransaction = _useContext10.foundTransaction,
|
|
@@ -62551,10 +62559,7 @@ var PaymentProvider = (function (props) {
|
|
|
62551
62559
|
confirmed: paymentConfirmed,
|
|
62552
62560
|
failed: paymentFailed
|
|
62553
62561
|
})).then(function (sentTransaction) {
|
|
62554
|
-
|
|
62555
|
-
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
62556
|
-
}
|
|
62557
|
-
|
|
62562
|
+
initializePaymentTracking(sentTransaction, currentBlock, payment.route);
|
|
62558
62563
|
setTransaction(sentTransaction);
|
|
62559
62564
|
})["catch"](function (error) {
|
|
62560
62565
|
console.log('error', error);
|
|
@@ -67687,10 +67692,10 @@ class PaymentRoute {
|
|
|
67687
67692
|
this.fromAddress = fromAddress;
|
|
67688
67693
|
this.fromToken = fromToken;
|
|
67689
67694
|
this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
|
|
67690
|
-
this.fromDecimals =
|
|
67695
|
+
this.fromDecimals = fromDecimals;
|
|
67691
67696
|
this.fromBalance = 0;
|
|
67692
67697
|
this.toToken = toToken;
|
|
67693
|
-
this.toAmount = _optionalChain([toAmount, 'optionalAccess',
|
|
67698
|
+
this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
67694
67699
|
this.toDecimals = toDecimals;
|
|
67695
67700
|
this.toAddress = toAddress;
|
|
67696
67701
|
this.toContract = toContract;
|
|
@@ -67754,12 +67759,14 @@ function convertToRoutes({ tokens, accept }) {
|
|
|
67754
67759
|
if(configuration.token && configuration.amount) {
|
|
67755
67760
|
let blockchain = configuration.blockchain;
|
|
67756
67761
|
let toToken = new Token({ blockchain, address: configuration.token });
|
|
67762
|
+
let fromDecimals = await fromToken.decimals();
|
|
67757
67763
|
let toDecimals = await toToken.decimals();
|
|
67758
67764
|
let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
|
|
67759
67765
|
|
|
67760
67766
|
return new PaymentRoute({
|
|
67761
67767
|
blockchain,
|
|
67762
67768
|
fromToken,
|
|
67769
|
+
fromDecimals,
|
|
67763
67770
|
toToken,
|
|
67764
67771
|
toAmount,
|
|
67765
67772
|
toDecimals,
|
|
@@ -67804,7 +67811,7 @@ async function route({ accept, whitelist, blacklist, apiKey, event, fee }) {
|
|
|
67804
67811
|
.then(addApproval)
|
|
67805
67812
|
.then(sortPaymentRoutes)
|
|
67806
67813
|
.then((routes)=>addTransactions({ routes, event, fee }))
|
|
67807
|
-
.then(
|
|
67814
|
+
.then(addRouteAmounts)
|
|
67808
67815
|
.then(filterDuplicateFromTokens);
|
|
67809
67816
|
|
|
67810
67817
|
return paymentRoutes
|
|
@@ -67937,16 +67944,19 @@ let addDirectTransferStatus = (routes) => {
|
|
|
67937
67944
|
})
|
|
67938
67945
|
};
|
|
67939
67946
|
|
|
67940
|
-
let
|
|
67947
|
+
let addRouteAmounts = (routes)=> {
|
|
67941
67948
|
return routes.map((route)=>{
|
|
67942
67949
|
if(route.directTransfer && !route.fee) {
|
|
67943
67950
|
if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
|
|
67944
67951
|
route.fromAmount = route.transaction.value;
|
|
67952
|
+
route.toAmount = route.transaction.value;
|
|
67945
67953
|
} else {
|
|
67946
67954
|
route.fromAmount = route.transaction.params[1];
|
|
67955
|
+
route.toAmount = route.transaction.params[1];
|
|
67947
67956
|
}
|
|
67948
67957
|
} else {
|
|
67949
67958
|
route.fromAmount = route.transaction.params.amounts[0];
|
|
67959
|
+
route.toAmount = route.transaction.params.amounts[1];
|
|
67950
67960
|
}
|
|
67951
67961
|
return route
|
|
67952
67962
|
})
|
|
@@ -68217,15 +68227,20 @@ var PaymentValueProvider = (function (props) {
|
|
|
68217
68227
|
paymentValue = _useState2[0],
|
|
68218
68228
|
setPaymentValue = _useState2[1];
|
|
68219
68229
|
|
|
68230
|
+
var _useState3 = react.useState(),
|
|
68231
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
68232
|
+
paymentValueLoss = _useState4[0],
|
|
68233
|
+
setPaymentValueLoss = _useState4[1];
|
|
68234
|
+
|
|
68220
68235
|
var _useContext5 = react.useContext(ConfigurationContext),
|
|
68221
68236
|
currency = _useContext5.currency;
|
|
68222
68237
|
|
|
68223
|
-
var
|
|
68224
|
-
|
|
68225
|
-
reloadCount =
|
|
68226
|
-
setReloadCount =
|
|
68238
|
+
var _useState5 = react.useState(0),
|
|
68239
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
68240
|
+
reloadCount = _useState6[0],
|
|
68241
|
+
setReloadCount = _useState6[1];
|
|
68227
68242
|
|
|
68228
|
-
var
|
|
68243
|
+
var updatePaymentValue = function updatePaymentValue(_ref) {
|
|
68229
68244
|
var updatable = _ref.updatable,
|
|
68230
68245
|
payment = _ref.payment;
|
|
68231
68246
|
|
|
@@ -68240,29 +68255,51 @@ var PaymentValueProvider = (function (props) {
|
|
|
68240
68255
|
amountIn: payment.route.toAmount,
|
|
68241
68256
|
fromAddress: account,
|
|
68242
68257
|
toAddress: account
|
|
68243
|
-
}),
|
|
68258
|
+
}), !payment.route.directTransfer ? route$8({
|
|
68259
|
+
blockchain: payment.route.blockchain,
|
|
68260
|
+
tokenIn: payment.route.toToken.address,
|
|
68261
|
+
tokenOut: payment.route.fromToken.address,
|
|
68262
|
+
amountIn: payment.route.toAmount,
|
|
68263
|
+
fromAddress: account,
|
|
68264
|
+
toAddress: account
|
|
68265
|
+
}) : Promise.resolve([]), new Token({
|
|
68244
68266
|
blockchain: payment.route.blockchain,
|
|
68245
68267
|
address: CONSTANTS$2[payment.route.blockchain].USD
|
|
68246
68268
|
}).decimals()]).then(function (_ref2) {
|
|
68247
|
-
var _ref3 = _slicedToArray(_ref2,
|
|
68248
|
-
|
|
68249
|
-
|
|
68269
|
+
var _ref3 = _slicedToArray(_ref2, 3),
|
|
68270
|
+
toTokenUSDExchangeRoutes = _ref3[0],
|
|
68271
|
+
reverseRoutes = _ref3[1],
|
|
68272
|
+
USDDecimals = _ref3[2];
|
|
68273
|
+
|
|
68274
|
+
var toTokenUSDRoute = toTokenUSDExchangeRoutes[0];
|
|
68275
|
+
var reverseRoute = reverseRoutes[0];
|
|
68250
68276
|
|
|
68251
|
-
|
|
68252
|
-
|
|
68277
|
+
if (reverseRoute) {
|
|
68278
|
+
var reverseAmountOutBN = BigNumber$4.from(reverseRoute.amountOut);
|
|
68279
|
+
var paymentAmountInBN = BigNumber$4.from(payment.route.fromAmount);
|
|
68280
|
+
var divPercent = 100 - reverseAmountOutBN.mul(BigNumber$4.from('100')).div(paymentAmountInBN).abs().toString();
|
|
68281
|
+
|
|
68282
|
+
if (divPercent > 5) {
|
|
68283
|
+
setPaymentValueLoss(divPercent);
|
|
68284
|
+
} else {
|
|
68285
|
+
setPaymentValueLoss(null);
|
|
68286
|
+
}
|
|
68287
|
+
}
|
|
68288
|
+
|
|
68289
|
+
var toTokenUSDAmount;
|
|
68253
68290
|
|
|
68254
68291
|
if (payment.route.toToken.address.toLowerCase() == CONSTANTS$2[payment.route.blockchain].USD.toLowerCase()) {
|
|
68255
|
-
|
|
68256
|
-
} else if (
|
|
68292
|
+
toTokenUSDAmount = payment.route.toAmount.toString();
|
|
68293
|
+
} else if (toTokenUSDRoute == undefined) {
|
|
68257
68294
|
setPaymentValue('');
|
|
68258
68295
|
return;
|
|
68259
68296
|
} else {
|
|
68260
|
-
|
|
68297
|
+
toTokenUSDAmount = toTokenUSDRoute.amountOut.toString();
|
|
68261
68298
|
}
|
|
68262
68299
|
|
|
68263
|
-
var
|
|
68300
|
+
var toTokenUSDValue = formatUnits(toTokenUSDAmount, USDDecimals);
|
|
68264
68301
|
Currency.fromUSD({
|
|
68265
|
-
amount:
|
|
68302
|
+
amount: toTokenUSDValue,
|
|
68266
68303
|
code: currency,
|
|
68267
68304
|
apiKey: apiKey
|
|
68268
68305
|
}).then(setPaymentValue)["catch"](setError);
|
|
@@ -68271,7 +68308,7 @@ var PaymentValueProvider = (function (props) {
|
|
|
68271
68308
|
|
|
68272
68309
|
react.useEffect(function () {
|
|
68273
68310
|
if (account && payment) {
|
|
68274
|
-
|
|
68311
|
+
updatePaymentValue({
|
|
68275
68312
|
updatable: updatable,
|
|
68276
68313
|
payment: payment
|
|
68277
68314
|
});
|
|
@@ -68280,7 +68317,7 @@ var PaymentValueProvider = (function (props) {
|
|
|
68280
68317
|
react.useEffect(function () {
|
|
68281
68318
|
var timeout = setTimeout(function () {
|
|
68282
68319
|
setReloadCount(reloadCount + 1);
|
|
68283
|
-
|
|
68320
|
+
updatePaymentValue({
|
|
68284
68321
|
updatable: updatable
|
|
68285
68322
|
});
|
|
68286
68323
|
}, 15000);
|
|
@@ -68290,7 +68327,8 @@ var PaymentValueProvider = (function (props) {
|
|
|
68290
68327
|
}, [reloadCount, updatable]);
|
|
68291
68328
|
return /*#__PURE__*/react.createElement(PaymentValueContext.Provider, {
|
|
68292
68329
|
value: {
|
|
68293
|
-
paymentValue: paymentValue
|
|
68330
|
+
paymentValue: paymentValue,
|
|
68331
|
+
paymentValueLoss: paymentValueLoss
|
|
68294
68332
|
}
|
|
68295
68333
|
}, props.children);
|
|
68296
68334
|
});
|
|
@@ -70036,6 +70074,7 @@ let TokenImage = function(props){
|
|
|
70036
70074
|
|
|
70037
70075
|
return(
|
|
70038
70076
|
react.createElement('img', {
|
|
70077
|
+
className: props.className ,
|
|
70039
70078
|
src: src ,
|
|
70040
70079
|
onError: handleLoadError , __self: this, __source: {fileName: _jsxFileName, lineNumber: 51}}
|
|
70041
70080
|
)
|
|
@@ -70438,7 +70477,8 @@ var Footer = (function () {
|
|
|
70438
70477
|
approvalTransaction = _useContext4.approvalTransaction;
|
|
70439
70478
|
|
|
70440
70479
|
var _useContext5 = react.useContext(PaymentValueContext),
|
|
70441
|
-
paymentValue = _useContext5.paymentValue
|
|
70480
|
+
paymentValue = _useContext5.paymentValue,
|
|
70481
|
+
paymentValueLoss = _useContext5.paymentValueLoss;
|
|
70442
70482
|
|
|
70443
70483
|
var _useContext6 = react.useContext(NavigateStackContext);
|
|
70444
70484
|
_useContext6.navigate;
|
|
@@ -70584,7 +70624,16 @@ var Footer = (function () {
|
|
|
70584
70624
|
displayedAmount = "".concat(payment.symbol, " ").concat(payment.amount);
|
|
70585
70625
|
}
|
|
70586
70626
|
|
|
70587
|
-
if (
|
|
70627
|
+
if (paymentValueLoss) {
|
|
70628
|
+
return /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement("div", {
|
|
70629
|
+
className: "PaddingBottomXS"
|
|
70630
|
+
}, /*#__PURE__*/react.createElement("div", {
|
|
70631
|
+
className: "Alert"
|
|
70632
|
+
}, /*#__PURE__*/react.createElement("strong", null, "Payment token would lose ", paymentValueLoss, "% of it's value!"))), /*#__PURE__*/react.createElement("button", {
|
|
70633
|
+
className: "ButtonPrimary disabled",
|
|
70634
|
+
onClick: function onClick() {}
|
|
70635
|
+
}, "Pay ", displayedAmount));
|
|
70636
|
+
} else if ((paymentState == 'initialized' || paymentState == 'approving') && payment.route) {
|
|
70588
70637
|
return /*#__PURE__*/react.createElement("button", {
|
|
70589
70638
|
className: ["ButtonPrimary", payment.route.approvalRequired && !payment.route.directTransfer ? 'disabled' : ''].join(' '),
|
|
70590
70639
|
onClick: function onClick() {
|
|
@@ -70882,11 +70931,11 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
70882
70931
|
paymentRoute = _useState6[0],
|
|
70883
70932
|
setPaymentRoute = _useState6[1];
|
|
70884
70933
|
|
|
70885
|
-
var _useState7 = react.useState(track &&
|
|
70934
|
+
var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
|
|
70886
70935
|
_useState8 = _slicedToArray(_useState7, 1),
|
|
70887
70936
|
tracking = _useState8[0];
|
|
70888
70937
|
|
|
70889
|
-
var _useState9 = react.useState(track && track.poll &&
|
|
70938
|
+
var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
|
|
70890
70939
|
_useState10 = _slicedToArray(_useState9, 1),
|
|
70891
70940
|
polling = _useState10[0];
|
|
70892
70941
|
|
|
@@ -70954,7 +71003,6 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
70954
71003
|
|
|
70955
71004
|
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70956
71005
|
attempt = parseInt(attempt || 1, 10);
|
|
70957
|
-
console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
|
|
70958
71006
|
|
|
70959
71007
|
if (attempt < 3) {
|
|
70960
71008
|
setTimeout(function () {
|
|
@@ -70997,9 +71045,7 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
70997
71045
|
after_block: afterBlock,
|
|
70998
71046
|
to_token: paymentRoute.toToken.address
|
|
70999
71047
|
}).then(function (response) {
|
|
71000
|
-
if (response.status
|
|
71001
|
-
console.log('PAYMENT TRACKING INITIALIZED');
|
|
71002
|
-
} else {
|
|
71048
|
+
if (response.status != 200) {
|
|
71003
71049
|
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
71004
71050
|
}
|
|
71005
71051
|
})["catch"](function (error) {
|
|
@@ -71063,7 +71109,56 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
71063
71109
|
};
|
|
71064
71110
|
}, [polling, transaction, afterBlock, paymentRoute]);
|
|
71065
71111
|
|
|
71112
|
+
var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
|
|
71113
|
+
if (attempt > 3) {
|
|
71114
|
+
return;
|
|
71115
|
+
}
|
|
71116
|
+
|
|
71117
|
+
fetch('https://api.depay.fi/v2/payments', {
|
|
71118
|
+
method: 'POST',
|
|
71119
|
+
headers: {
|
|
71120
|
+
'X-Api-Key': apiKey,
|
|
71121
|
+
'Content-Type': 'application/json'
|
|
71122
|
+
},
|
|
71123
|
+
body: JSON.stringify({
|
|
71124
|
+
blockchain: transaction.blockchain,
|
|
71125
|
+
transaction: transaction.id,
|
|
71126
|
+
sender: transaction.from.toLowerCase(),
|
|
71127
|
+
nonce: transaction.nonce,
|
|
71128
|
+
receiver: paymentRoute.toAddress,
|
|
71129
|
+
token: paymentRoute.toToken.address,
|
|
71130
|
+
amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
|
|
71131
|
+
confirmations: 1,
|
|
71132
|
+
after_block: afterBlock,
|
|
71133
|
+
uuid: transaction.id,
|
|
71134
|
+
payload: {
|
|
71135
|
+
sender_id: transaction.from.toLowerCase(),
|
|
71136
|
+
sender_token_id: paymentRoute.fromToken.address,
|
|
71137
|
+
sender_amount: formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
|
|
71138
|
+
},
|
|
71139
|
+
fee_amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
|
|
71140
|
+
fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
|
|
71141
|
+
})
|
|
71142
|
+
}).then(function (response) {
|
|
71143
|
+
if (response.status == 200 || response.status == 201) ; else {
|
|
71144
|
+
setTimeout(function () {
|
|
71145
|
+
storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
71146
|
+
}, 3000);
|
|
71147
|
+
}
|
|
71148
|
+
})["catch"](function (error) {
|
|
71149
|
+
setTimeout(function () {
|
|
71150
|
+
storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
71151
|
+
}, 3000);
|
|
71152
|
+
});
|
|
71153
|
+
};
|
|
71154
|
+
|
|
71066
71155
|
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
71156
|
+
storePayment(transaction, afterBlock, paymentRoute, 1);
|
|
71157
|
+
|
|
71158
|
+
if (tracking == false) {
|
|
71159
|
+
return;
|
|
71160
|
+
}
|
|
71161
|
+
|
|
71067
71162
|
setTransaction(transaction);
|
|
71068
71163
|
setAfterBlock(afterBlock);
|
|
71069
71164
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -2769,15 +2766,20 @@ var PaymentValueProvider = (function (props) {
|
|
|
2769
2766
|
paymentValue = _useState2[0],
|
|
2770
2767
|
setPaymentValue = _useState2[1];
|
|
2771
2768
|
|
|
2769
|
+
var _useState3 = useState(),
|
|
2770
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
2771
|
+
paymentValueLoss = _useState4[0],
|
|
2772
|
+
setPaymentValueLoss = _useState4[1];
|
|
2773
|
+
|
|
2772
2774
|
var _useContext5 = useContext(ConfigurationContext),
|
|
2773
2775
|
currency = _useContext5.currency;
|
|
2774
2776
|
|
|
2775
|
-
var
|
|
2776
|
-
|
|
2777
|
-
reloadCount =
|
|
2778
|
-
setReloadCount =
|
|
2777
|
+
var _useState5 = useState(0),
|
|
2778
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
2779
|
+
reloadCount = _useState6[0],
|
|
2780
|
+
setReloadCount = _useState6[1];
|
|
2779
2781
|
|
|
2780
|
-
var
|
|
2782
|
+
var updatePaymentValue = function updatePaymentValue(_ref) {
|
|
2781
2783
|
var updatable = _ref.updatable,
|
|
2782
2784
|
payment = _ref.payment;
|
|
2783
2785
|
|
|
@@ -2792,29 +2794,51 @@ var PaymentValueProvider = (function (props) {
|
|
|
2792
2794
|
amountIn: payment.route.toAmount,
|
|
2793
2795
|
fromAddress: account,
|
|
2794
2796
|
toAddress: account
|
|
2795
|
-
}),
|
|
2797
|
+
}), !payment.route.directTransfer ? route({
|
|
2798
|
+
blockchain: payment.route.blockchain,
|
|
2799
|
+
tokenIn: payment.route.toToken.address,
|
|
2800
|
+
tokenOut: payment.route.fromToken.address,
|
|
2801
|
+
amountIn: payment.route.toAmount,
|
|
2802
|
+
fromAddress: account,
|
|
2803
|
+
toAddress: account
|
|
2804
|
+
}) : Promise.resolve([]), new Token({
|
|
2796
2805
|
blockchain: payment.route.blockchain,
|
|
2797
2806
|
address: CONSTANTS[payment.route.blockchain].USD
|
|
2798
2807
|
}).decimals()]).then(function (_ref2) {
|
|
2799
|
-
var _ref3 = _slicedToArray(_ref2,
|
|
2800
|
-
|
|
2801
|
-
|
|
2808
|
+
var _ref3 = _slicedToArray(_ref2, 3),
|
|
2809
|
+
toTokenUSDExchangeRoutes = _ref3[0],
|
|
2810
|
+
reverseRoutes = _ref3[1],
|
|
2811
|
+
USDDecimals = _ref3[2];
|
|
2812
|
+
|
|
2813
|
+
var toTokenUSDRoute = toTokenUSDExchangeRoutes[0];
|
|
2814
|
+
var reverseRoute = reverseRoutes[0];
|
|
2815
|
+
|
|
2816
|
+
if (reverseRoute) {
|
|
2817
|
+
var reverseAmountOutBN = ethers.BigNumber.from(reverseRoute.amountOut);
|
|
2818
|
+
var paymentAmountInBN = ethers.BigNumber.from(payment.route.fromAmount);
|
|
2819
|
+
var divPercent = 100 - reverseAmountOutBN.mul(ethers.BigNumber.from('100')).div(paymentAmountInBN).abs().toString();
|
|
2820
|
+
|
|
2821
|
+
if (divPercent > 5) {
|
|
2822
|
+
setPaymentValueLoss(divPercent);
|
|
2823
|
+
} else {
|
|
2824
|
+
setPaymentValueLoss(null);
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2802
2827
|
|
|
2803
|
-
var
|
|
2804
|
-
var USDAmount;
|
|
2828
|
+
var toTokenUSDAmount;
|
|
2805
2829
|
|
|
2806
2830
|
if (payment.route.toToken.address.toLowerCase() == CONSTANTS[payment.route.blockchain].USD.toLowerCase()) {
|
|
2807
|
-
|
|
2808
|
-
} else if (
|
|
2831
|
+
toTokenUSDAmount = payment.route.toAmount.toString();
|
|
2832
|
+
} else if (toTokenUSDRoute == undefined) {
|
|
2809
2833
|
setPaymentValue('');
|
|
2810
2834
|
return;
|
|
2811
2835
|
} else {
|
|
2812
|
-
|
|
2836
|
+
toTokenUSDAmount = toTokenUSDRoute.amountOut.toString();
|
|
2813
2837
|
}
|
|
2814
2838
|
|
|
2815
|
-
var
|
|
2839
|
+
var toTokenUSDValue = ethers.utils.formatUnits(toTokenUSDAmount, USDDecimals);
|
|
2816
2840
|
Currency.fromUSD({
|
|
2817
|
-
amount:
|
|
2841
|
+
amount: toTokenUSDValue,
|
|
2818
2842
|
code: currency,
|
|
2819
2843
|
apiKey: apiKey
|
|
2820
2844
|
}).then(setPaymentValue)["catch"](setError);
|
|
@@ -2823,7 +2847,7 @@ var PaymentValueProvider = (function (props) {
|
|
|
2823
2847
|
|
|
2824
2848
|
useEffect(function () {
|
|
2825
2849
|
if (account && payment) {
|
|
2826
|
-
|
|
2850
|
+
updatePaymentValue({
|
|
2827
2851
|
updatable: updatable,
|
|
2828
2852
|
payment: payment
|
|
2829
2853
|
});
|
|
@@ -2832,7 +2856,7 @@ var PaymentValueProvider = (function (props) {
|
|
|
2832
2856
|
useEffect(function () {
|
|
2833
2857
|
var timeout = setTimeout(function () {
|
|
2834
2858
|
setReloadCount(reloadCount + 1);
|
|
2835
|
-
|
|
2859
|
+
updatePaymentValue({
|
|
2836
2860
|
updatable: updatable
|
|
2837
2861
|
});
|
|
2838
2862
|
}, 15000);
|
|
@@ -2842,7 +2866,8 @@ var PaymentValueProvider = (function (props) {
|
|
|
2842
2866
|
}, [reloadCount, updatable]);
|
|
2843
2867
|
return /*#__PURE__*/React.createElement(PaymentValueContext.Provider, {
|
|
2844
2868
|
value: {
|
|
2845
|
-
paymentValue: paymentValue
|
|
2869
|
+
paymentValue: paymentValue,
|
|
2870
|
+
paymentValueLoss: paymentValueLoss
|
|
2846
2871
|
}
|
|
2847
2872
|
}, props.children);
|
|
2848
2873
|
});
|
|
@@ -3276,7 +3301,8 @@ var Footer = (function () {
|
|
|
3276
3301
|
approvalTransaction = _useContext4.approvalTransaction;
|
|
3277
3302
|
|
|
3278
3303
|
var _useContext5 = useContext(PaymentValueContext),
|
|
3279
|
-
paymentValue = _useContext5.paymentValue
|
|
3304
|
+
paymentValue = _useContext5.paymentValue,
|
|
3305
|
+
paymentValueLoss = _useContext5.paymentValueLoss;
|
|
3280
3306
|
|
|
3281
3307
|
var _useContext6 = useContext(NavigateStackContext);
|
|
3282
3308
|
_useContext6.navigate;
|
|
@@ -3422,7 +3448,16 @@ var Footer = (function () {
|
|
|
3422
3448
|
displayedAmount = "".concat(payment.symbol, " ").concat(payment.amount);
|
|
3423
3449
|
}
|
|
3424
3450
|
|
|
3425
|
-
if (
|
|
3451
|
+
if (paymentValueLoss) {
|
|
3452
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
3453
|
+
className: "PaddingBottomXS"
|
|
3454
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
3455
|
+
className: "Alert"
|
|
3456
|
+
}, /*#__PURE__*/React.createElement("strong", null, "Payment token would lose ", paymentValueLoss, "% of it's value!"))), /*#__PURE__*/React.createElement("button", {
|
|
3457
|
+
className: "ButtonPrimary disabled",
|
|
3458
|
+
onClick: function onClick() {}
|
|
3459
|
+
}, "Pay ", displayedAmount));
|
|
3460
|
+
} else if ((paymentState == 'initialized' || paymentState == 'approving') && payment.route) {
|
|
3426
3461
|
return /*#__PURE__*/React.createElement("button", {
|
|
3427
3462
|
className: ["ButtonPrimary", payment.route.approvalRequired && !payment.route.directTransfer ? 'disabled' : ''].join(' '),
|
|
3428
3463
|
onClick: function onClick() {
|
|
@@ -3720,11 +3755,11 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
3720
3755
|
paymentRoute = _useState6[0],
|
|
3721
3756
|
setPaymentRoute = _useState6[1];
|
|
3722
3757
|
|
|
3723
|
-
var _useState7 = useState(track &&
|
|
3758
|
+
var _useState7 = useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
|
|
3724
3759
|
_useState8 = _slicedToArray(_useState7, 1),
|
|
3725
3760
|
tracking = _useState8[0];
|
|
3726
3761
|
|
|
3727
|
-
var _useState9 = useState(track && track.poll &&
|
|
3762
|
+
var _useState9 = useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
|
|
3728
3763
|
_useState10 = _slicedToArray(_useState9, 1),
|
|
3729
3764
|
polling = _useState10[0];
|
|
3730
3765
|
|
|
@@ -3792,7 +3827,6 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
3792
3827
|
|
|
3793
3828
|
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
3794
3829
|
attempt = parseInt(attempt || 1, 10);
|
|
3795
|
-
console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
|
|
3796
3830
|
|
|
3797
3831
|
if (attempt < 3) {
|
|
3798
3832
|
setTimeout(function () {
|
|
@@ -3835,9 +3869,7 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
3835
3869
|
after_block: afterBlock,
|
|
3836
3870
|
to_token: paymentRoute.toToken.address
|
|
3837
3871
|
}).then(function (response) {
|
|
3838
|
-
if (response.status
|
|
3839
|
-
console.log('PAYMENT TRACKING INITIALIZED');
|
|
3840
|
-
} else {
|
|
3872
|
+
if (response.status != 200) {
|
|
3841
3873
|
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
3842
3874
|
}
|
|
3843
3875
|
})["catch"](function (error) {
|
|
@@ -3901,7 +3933,56 @@ var PaymentTrackingProvider = (function (props) {
|
|
|
3901
3933
|
};
|
|
3902
3934
|
}, [polling, transaction, afterBlock, paymentRoute]);
|
|
3903
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
|
+
|
|
3904
3979
|
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
3980
|
+
storePayment(transaction, afterBlock, paymentRoute, 1);
|
|
3981
|
+
|
|
3982
|
+
if (tracking == false) {
|
|
3983
|
+
return;
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3905
3986
|
setTransaction(transaction);
|
|
3906
3987
|
setAfterBlock(afterBlock);
|
|
3907
3988
|
setPaymentRoute(paymentRoute);
|
package/dist/umd/index.bundle.js
CHANGED
|
@@ -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 = {
|
|
@@ -49031,7 +49035,7 @@
|
|
|
49031
49035
|
const instances = {};
|
|
49032
49036
|
|
|
49033
49037
|
const getWalletClass = function(){
|
|
49034
|
-
if(
|
|
49038
|
+
if(getConnectedInstance()) {
|
|
49035
49039
|
return wallets.WalletConnect
|
|
49036
49040
|
} else if (typeof window.ethereum === 'object' && window.ethereum.isMetaMask) {
|
|
49037
49041
|
return wallets.MetaMask
|
|
@@ -49046,8 +49050,8 @@
|
|
|
49046
49050
|
const walletClass = getWalletClass();
|
|
49047
49051
|
const existingInstance = instances[walletClass];
|
|
49048
49052
|
|
|
49049
|
-
if(
|
|
49050
|
-
return
|
|
49053
|
+
if(getConnectedInstance()) {
|
|
49054
|
+
return getConnectedInstance()
|
|
49051
49055
|
} else if(existingInstance) {
|
|
49052
49056
|
return existingInstance
|
|
49053
49057
|
} else if(walletClass) {
|
|
@@ -55321,17 +55325,21 @@
|
|
|
55321
55325
|
if (this.address == CONSTANTS$2[this.blockchain].NATIVE) {
|
|
55322
55326
|
return CONSTANTS$2[this.blockchain].DECIMALS
|
|
55323
55327
|
}
|
|
55324
|
-
|
|
55325
|
-
|
|
55326
|
-
|
|
55327
|
-
|
|
55328
|
-
|
|
55329
|
-
|
|
55330
|
-
|
|
55331
|
-
|
|
55332
|
-
|
|
55333
|
-
|
|
55334
|
-
|
|
55328
|
+
let decimals = 0;
|
|
55329
|
+
try {
|
|
55330
|
+
decimals = await request(
|
|
55331
|
+
{
|
|
55332
|
+
blockchain: this.blockchain,
|
|
55333
|
+
address: this.address,
|
|
55334
|
+
method: 'decimals',
|
|
55335
|
+
},
|
|
55336
|
+
{
|
|
55337
|
+
api: Token[this.blockchain].DEFAULT,
|
|
55338
|
+
cache: 86400000, // 1 day
|
|
55339
|
+
},
|
|
55340
|
+
);
|
|
55341
|
+
} catch (e) {}
|
|
55342
|
+
return decimals
|
|
55335
55343
|
}
|
|
55336
55344
|
|
|
55337
55345
|
async symbol() {
|
|
@@ -62477,7 +62485,7 @@
|
|
|
62477
62485
|
var _useContext9 = react.useContext(PaymentTrackingContext),
|
|
62478
62486
|
release = _useContext9.release,
|
|
62479
62487
|
tracking = _useContext9.tracking,
|
|
62480
|
-
|
|
62488
|
+
initializePaymentTracking = _useContext9.initializeTracking;
|
|
62481
62489
|
|
|
62482
62490
|
var _useContext10 = react.useContext(TransactionTrackingContext),
|
|
62483
62491
|
foundTransaction = _useContext10.foundTransaction,
|
|
@@ -62557,10 +62565,7 @@
|
|
|
62557
62565
|
confirmed: paymentConfirmed,
|
|
62558
62566
|
failed: paymentFailed
|
|
62559
62567
|
})).then(function (sentTransaction) {
|
|
62560
|
-
|
|
62561
|
-
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
62562
|
-
}
|
|
62563
|
-
|
|
62568
|
+
initializePaymentTracking(sentTransaction, currentBlock, payment.route);
|
|
62564
62569
|
setTransaction(sentTransaction);
|
|
62565
62570
|
})["catch"](function (error) {
|
|
62566
62571
|
console.log('error', error);
|
|
@@ -67693,10 +67698,10 @@
|
|
|
67693
67698
|
this.fromAddress = fromAddress;
|
|
67694
67699
|
this.fromToken = fromToken;
|
|
67695
67700
|
this.fromAmount = _optionalChain([fromAmount, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]);
|
|
67696
|
-
this.fromDecimals =
|
|
67701
|
+
this.fromDecimals = fromDecimals;
|
|
67697
67702
|
this.fromBalance = 0;
|
|
67698
67703
|
this.toToken = toToken;
|
|
67699
|
-
this.toAmount = _optionalChain([toAmount, 'optionalAccess',
|
|
67704
|
+
this.toAmount = _optionalChain([toAmount, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
67700
67705
|
this.toDecimals = toDecimals;
|
|
67701
67706
|
this.toAddress = toAddress;
|
|
67702
67707
|
this.toContract = toContract;
|
|
@@ -67760,12 +67765,14 @@
|
|
|
67760
67765
|
if(configuration.token && configuration.amount) {
|
|
67761
67766
|
let blockchain = configuration.blockchain;
|
|
67762
67767
|
let toToken = new Token({ blockchain, address: configuration.token });
|
|
67768
|
+
let fromDecimals = await fromToken.decimals();
|
|
67763
67769
|
let toDecimals = await toToken.decimals();
|
|
67764
67770
|
let toAmount = (await toToken.BigNumber(configuration.amount)).toString();
|
|
67765
67771
|
|
|
67766
67772
|
return new PaymentRoute({
|
|
67767
67773
|
blockchain,
|
|
67768
67774
|
fromToken,
|
|
67775
|
+
fromDecimals,
|
|
67769
67776
|
toToken,
|
|
67770
67777
|
toAmount,
|
|
67771
67778
|
toDecimals,
|
|
@@ -67810,7 +67817,7 @@
|
|
|
67810
67817
|
.then(addApproval)
|
|
67811
67818
|
.then(sortPaymentRoutes)
|
|
67812
67819
|
.then((routes)=>addTransactions({ routes, event, fee }))
|
|
67813
|
-
.then(
|
|
67820
|
+
.then(addRouteAmounts)
|
|
67814
67821
|
.then(filterDuplicateFromTokens);
|
|
67815
67822
|
|
|
67816
67823
|
return paymentRoutes
|
|
@@ -67943,16 +67950,19 @@
|
|
|
67943
67950
|
})
|
|
67944
67951
|
};
|
|
67945
67952
|
|
|
67946
|
-
let
|
|
67953
|
+
let addRouteAmounts = (routes)=> {
|
|
67947
67954
|
return routes.map((route)=>{
|
|
67948
67955
|
if(route.directTransfer && !route.fee) {
|
|
67949
67956
|
if(route.fromToken.address.toLowerCase() == CONSTANTS$2[route.blockchain].NATIVE.toLowerCase()) {
|
|
67950
67957
|
route.fromAmount = route.transaction.value;
|
|
67958
|
+
route.toAmount = route.transaction.value;
|
|
67951
67959
|
} else {
|
|
67952
67960
|
route.fromAmount = route.transaction.params[1];
|
|
67961
|
+
route.toAmount = route.transaction.params[1];
|
|
67953
67962
|
}
|
|
67954
67963
|
} else {
|
|
67955
67964
|
route.fromAmount = route.transaction.params.amounts[0];
|
|
67965
|
+
route.toAmount = route.transaction.params.amounts[1];
|
|
67956
67966
|
}
|
|
67957
67967
|
return route
|
|
67958
67968
|
})
|
|
@@ -68223,15 +68233,20 @@
|
|
|
68223
68233
|
paymentValue = _useState2[0],
|
|
68224
68234
|
setPaymentValue = _useState2[1];
|
|
68225
68235
|
|
|
68236
|
+
var _useState3 = react.useState(),
|
|
68237
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
68238
|
+
paymentValueLoss = _useState4[0],
|
|
68239
|
+
setPaymentValueLoss = _useState4[1];
|
|
68240
|
+
|
|
68226
68241
|
var _useContext5 = react.useContext(ConfigurationContext),
|
|
68227
68242
|
currency = _useContext5.currency;
|
|
68228
68243
|
|
|
68229
|
-
var
|
|
68230
|
-
|
|
68231
|
-
reloadCount =
|
|
68232
|
-
setReloadCount =
|
|
68244
|
+
var _useState5 = react.useState(0),
|
|
68245
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
68246
|
+
reloadCount = _useState6[0],
|
|
68247
|
+
setReloadCount = _useState6[1];
|
|
68233
68248
|
|
|
68234
|
-
var
|
|
68249
|
+
var updatePaymentValue = function updatePaymentValue(_ref) {
|
|
68235
68250
|
var updatable = _ref.updatable,
|
|
68236
68251
|
payment = _ref.payment;
|
|
68237
68252
|
|
|
@@ -68246,29 +68261,51 @@
|
|
|
68246
68261
|
amountIn: payment.route.toAmount,
|
|
68247
68262
|
fromAddress: account,
|
|
68248
68263
|
toAddress: account
|
|
68249
|
-
}),
|
|
68264
|
+
}), !payment.route.directTransfer ? route$8({
|
|
68265
|
+
blockchain: payment.route.blockchain,
|
|
68266
|
+
tokenIn: payment.route.toToken.address,
|
|
68267
|
+
tokenOut: payment.route.fromToken.address,
|
|
68268
|
+
amountIn: payment.route.toAmount,
|
|
68269
|
+
fromAddress: account,
|
|
68270
|
+
toAddress: account
|
|
68271
|
+
}) : Promise.resolve([]), new Token({
|
|
68250
68272
|
blockchain: payment.route.blockchain,
|
|
68251
68273
|
address: CONSTANTS$2[payment.route.blockchain].USD
|
|
68252
68274
|
}).decimals()]).then(function (_ref2) {
|
|
68253
|
-
var _ref3 = _slicedToArray(_ref2,
|
|
68254
|
-
|
|
68255
|
-
|
|
68275
|
+
var _ref3 = _slicedToArray(_ref2, 3),
|
|
68276
|
+
toTokenUSDExchangeRoutes = _ref3[0],
|
|
68277
|
+
reverseRoutes = _ref3[1],
|
|
68278
|
+
USDDecimals = _ref3[2];
|
|
68279
|
+
|
|
68280
|
+
var toTokenUSDRoute = toTokenUSDExchangeRoutes[0];
|
|
68281
|
+
var reverseRoute = reverseRoutes[0];
|
|
68256
68282
|
|
|
68257
|
-
|
|
68258
|
-
|
|
68283
|
+
if (reverseRoute) {
|
|
68284
|
+
var reverseAmountOutBN = BigNumber$4.from(reverseRoute.amountOut);
|
|
68285
|
+
var paymentAmountInBN = BigNumber$4.from(payment.route.fromAmount);
|
|
68286
|
+
var divPercent = 100 - reverseAmountOutBN.mul(BigNumber$4.from('100')).div(paymentAmountInBN).abs().toString();
|
|
68287
|
+
|
|
68288
|
+
if (divPercent > 5) {
|
|
68289
|
+
setPaymentValueLoss(divPercent);
|
|
68290
|
+
} else {
|
|
68291
|
+
setPaymentValueLoss(null);
|
|
68292
|
+
}
|
|
68293
|
+
}
|
|
68294
|
+
|
|
68295
|
+
var toTokenUSDAmount;
|
|
68259
68296
|
|
|
68260
68297
|
if (payment.route.toToken.address.toLowerCase() == CONSTANTS$2[payment.route.blockchain].USD.toLowerCase()) {
|
|
68261
|
-
|
|
68262
|
-
} else if (
|
|
68298
|
+
toTokenUSDAmount = payment.route.toAmount.toString();
|
|
68299
|
+
} else if (toTokenUSDRoute == undefined) {
|
|
68263
68300
|
setPaymentValue('');
|
|
68264
68301
|
return;
|
|
68265
68302
|
} else {
|
|
68266
|
-
|
|
68303
|
+
toTokenUSDAmount = toTokenUSDRoute.amountOut.toString();
|
|
68267
68304
|
}
|
|
68268
68305
|
|
|
68269
|
-
var
|
|
68306
|
+
var toTokenUSDValue = formatUnits(toTokenUSDAmount, USDDecimals);
|
|
68270
68307
|
Currency.fromUSD({
|
|
68271
|
-
amount:
|
|
68308
|
+
amount: toTokenUSDValue,
|
|
68272
68309
|
code: currency,
|
|
68273
68310
|
apiKey: apiKey
|
|
68274
68311
|
}).then(setPaymentValue)["catch"](setError);
|
|
@@ -68277,7 +68314,7 @@
|
|
|
68277
68314
|
|
|
68278
68315
|
react.useEffect(function () {
|
|
68279
68316
|
if (account && payment) {
|
|
68280
|
-
|
|
68317
|
+
updatePaymentValue({
|
|
68281
68318
|
updatable: updatable,
|
|
68282
68319
|
payment: payment
|
|
68283
68320
|
});
|
|
@@ -68286,7 +68323,7 @@
|
|
|
68286
68323
|
react.useEffect(function () {
|
|
68287
68324
|
var timeout = setTimeout(function () {
|
|
68288
68325
|
setReloadCount(reloadCount + 1);
|
|
68289
|
-
|
|
68326
|
+
updatePaymentValue({
|
|
68290
68327
|
updatable: updatable
|
|
68291
68328
|
});
|
|
68292
68329
|
}, 15000);
|
|
@@ -68296,7 +68333,8 @@
|
|
|
68296
68333
|
}, [reloadCount, updatable]);
|
|
68297
68334
|
return /*#__PURE__*/react.createElement(PaymentValueContext.Provider, {
|
|
68298
68335
|
value: {
|
|
68299
|
-
paymentValue: paymentValue
|
|
68336
|
+
paymentValue: paymentValue,
|
|
68337
|
+
paymentValueLoss: paymentValueLoss
|
|
68300
68338
|
}
|
|
68301
68339
|
}, props.children);
|
|
68302
68340
|
});
|
|
@@ -70042,6 +70080,7 @@
|
|
|
70042
70080
|
|
|
70043
70081
|
return(
|
|
70044
70082
|
react.createElement('img', {
|
|
70083
|
+
className: props.className ,
|
|
70045
70084
|
src: src ,
|
|
70046
70085
|
onError: handleLoadError , __self: this, __source: {fileName: _jsxFileName, lineNumber: 51}}
|
|
70047
70086
|
)
|
|
@@ -70444,7 +70483,8 @@
|
|
|
70444
70483
|
approvalTransaction = _useContext4.approvalTransaction;
|
|
70445
70484
|
|
|
70446
70485
|
var _useContext5 = react.useContext(PaymentValueContext),
|
|
70447
|
-
paymentValue = _useContext5.paymentValue
|
|
70486
|
+
paymentValue = _useContext5.paymentValue,
|
|
70487
|
+
paymentValueLoss = _useContext5.paymentValueLoss;
|
|
70448
70488
|
|
|
70449
70489
|
var _useContext6 = react.useContext(NavigateStackContext);
|
|
70450
70490
|
_useContext6.navigate;
|
|
@@ -70590,7 +70630,16 @@
|
|
|
70590
70630
|
displayedAmount = "".concat(payment.symbol, " ").concat(payment.amount);
|
|
70591
70631
|
}
|
|
70592
70632
|
|
|
70593
|
-
if (
|
|
70633
|
+
if (paymentValueLoss) {
|
|
70634
|
+
return /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement("div", {
|
|
70635
|
+
className: "PaddingBottomXS"
|
|
70636
|
+
}, /*#__PURE__*/react.createElement("div", {
|
|
70637
|
+
className: "Alert"
|
|
70638
|
+
}, /*#__PURE__*/react.createElement("strong", null, "Payment token would lose ", paymentValueLoss, "% of it's value!"))), /*#__PURE__*/react.createElement("button", {
|
|
70639
|
+
className: "ButtonPrimary disabled",
|
|
70640
|
+
onClick: function onClick() {}
|
|
70641
|
+
}, "Pay ", displayedAmount));
|
|
70642
|
+
} else if ((paymentState == 'initialized' || paymentState == 'approving') && payment.route) {
|
|
70594
70643
|
return /*#__PURE__*/react.createElement("button", {
|
|
70595
70644
|
className: ["ButtonPrimary", payment.route.approvalRequired && !payment.route.directTransfer ? 'disabled' : ''].join(' '),
|
|
70596
70645
|
onClick: function onClick() {
|
|
@@ -70888,11 +70937,11 @@
|
|
|
70888
70937
|
paymentRoute = _useState6[0],
|
|
70889
70938
|
setPaymentRoute = _useState6[1];
|
|
70890
70939
|
|
|
70891
|
-
var _useState7 = react.useState(track &&
|
|
70940
|
+
var _useState7 = react.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
|
|
70892
70941
|
_useState8 = _slicedToArray(_useState7, 1),
|
|
70893
70942
|
tracking = _useState8[0];
|
|
70894
70943
|
|
|
70895
|
-
var _useState9 = react.useState(track && track.poll &&
|
|
70944
|
+
var _useState9 = react.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
|
|
70896
70945
|
_useState10 = _slicedToArray(_useState9, 1),
|
|
70897
70946
|
polling = _useState10[0];
|
|
70898
70947
|
|
|
@@ -70960,7 +71009,6 @@
|
|
|
70960
71009
|
|
|
70961
71010
|
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70962
71011
|
attempt = parseInt(attempt || 1, 10);
|
|
70963
|
-
console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
|
|
70964
71012
|
|
|
70965
71013
|
if (attempt < 3) {
|
|
70966
71014
|
setTimeout(function () {
|
|
@@ -71003,9 +71051,7 @@
|
|
|
71003
71051
|
after_block: afterBlock,
|
|
71004
71052
|
to_token: paymentRoute.toToken.address
|
|
71005
71053
|
}).then(function (response) {
|
|
71006
|
-
if (response.status
|
|
71007
|
-
console.log('PAYMENT TRACKING INITIALIZED');
|
|
71008
|
-
} else {
|
|
71054
|
+
if (response.status != 200) {
|
|
71009
71055
|
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
71010
71056
|
}
|
|
71011
71057
|
})["catch"](function (error) {
|
|
@@ -71069,7 +71115,56 @@
|
|
|
71069
71115
|
};
|
|
71070
71116
|
}, [polling, transaction, afterBlock, paymentRoute]);
|
|
71071
71117
|
|
|
71118
|
+
var storePayment = function storePayment(transaction, afterBlock, paymentRoute, attempt) {
|
|
71119
|
+
if (attempt > 3) {
|
|
71120
|
+
return;
|
|
71121
|
+
}
|
|
71122
|
+
|
|
71123
|
+
fetch('https://api.depay.fi/v2/payments', {
|
|
71124
|
+
method: 'POST',
|
|
71125
|
+
headers: {
|
|
71126
|
+
'X-Api-Key': apiKey,
|
|
71127
|
+
'Content-Type': 'application/json'
|
|
71128
|
+
},
|
|
71129
|
+
body: JSON.stringify({
|
|
71130
|
+
blockchain: transaction.blockchain,
|
|
71131
|
+
transaction: transaction.id,
|
|
71132
|
+
sender: transaction.from.toLowerCase(),
|
|
71133
|
+
nonce: transaction.nonce,
|
|
71134
|
+
receiver: paymentRoute.toAddress,
|
|
71135
|
+
token: paymentRoute.toToken.address,
|
|
71136
|
+
amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[1], paymentRoute.toDecimals) : formatUnits(paymentRoute.toAmount, paymentRoute.toDecimals),
|
|
71137
|
+
confirmations: 1,
|
|
71138
|
+
after_block: afterBlock,
|
|
71139
|
+
uuid: transaction.id,
|
|
71140
|
+
payload: {
|
|
71141
|
+
sender_id: transaction.from.toLowerCase(),
|
|
71142
|
+
sender_token_id: paymentRoute.fromToken.address,
|
|
71143
|
+
sender_amount: formatUnits(paymentRoute.fromAmount, paymentRoute.fromDecimals)
|
|
71144
|
+
},
|
|
71145
|
+
fee_amount: paymentRoute.fee ? formatUnits(paymentRoute.transaction.params.amounts[4], paymentRoute.toDecimals) : null,
|
|
71146
|
+
fee_receiver: paymentRoute.fee ? paymentRoute.transaction.params.addresses[1] : null
|
|
71147
|
+
})
|
|
71148
|
+
}).then(function (response) {
|
|
71149
|
+
if (response.status == 200 || response.status == 201) ; else {
|
|
71150
|
+
setTimeout(function () {
|
|
71151
|
+
storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
71152
|
+
}, 3000);
|
|
71153
|
+
}
|
|
71154
|
+
})["catch"](function (error) {
|
|
71155
|
+
setTimeout(function () {
|
|
71156
|
+
storePayment(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
71157
|
+
}, 3000);
|
|
71158
|
+
});
|
|
71159
|
+
};
|
|
71160
|
+
|
|
71072
71161
|
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
71162
|
+
storePayment(transaction, afterBlock, paymentRoute, 1);
|
|
71163
|
+
|
|
71164
|
+
if (tracking == false) {
|
|
71165
|
+
return;
|
|
71166
|
+
}
|
|
71167
|
+
|
|
71073
71168
|
setTransaction(transaction);
|
|
71074
71169
|
setAfterBlock(afterBlock);
|
|
71075
71170
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -2764,15 +2761,20 @@
|
|
|
2764
2761
|
paymentValue = _useState2[0],
|
|
2765
2762
|
setPaymentValue = _useState2[1];
|
|
2766
2763
|
|
|
2764
|
+
var _useState3 = React.useState(),
|
|
2765
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
2766
|
+
paymentValueLoss = _useState4[0],
|
|
2767
|
+
setPaymentValueLoss = _useState4[1];
|
|
2768
|
+
|
|
2767
2769
|
var _useContext5 = React.useContext(ConfigurationContext),
|
|
2768
2770
|
currency = _useContext5.currency;
|
|
2769
2771
|
|
|
2770
|
-
var
|
|
2771
|
-
|
|
2772
|
-
reloadCount =
|
|
2773
|
-
setReloadCount =
|
|
2772
|
+
var _useState5 = React.useState(0),
|
|
2773
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
2774
|
+
reloadCount = _useState6[0],
|
|
2775
|
+
setReloadCount = _useState6[1];
|
|
2774
2776
|
|
|
2775
|
-
var
|
|
2777
|
+
var updatePaymentValue = function updatePaymentValue(_ref) {
|
|
2776
2778
|
var updatable = _ref.updatable,
|
|
2777
2779
|
payment = _ref.payment;
|
|
2778
2780
|
|
|
@@ -2787,29 +2789,51 @@
|
|
|
2787
2789
|
amountIn: payment.route.toAmount,
|
|
2788
2790
|
fromAddress: account,
|
|
2789
2791
|
toAddress: account
|
|
2790
|
-
}),
|
|
2792
|
+
}), !payment.route.directTransfer ? web3Exchanges.route({
|
|
2793
|
+
blockchain: payment.route.blockchain,
|
|
2794
|
+
tokenIn: payment.route.toToken.address,
|
|
2795
|
+
tokenOut: payment.route.fromToken.address,
|
|
2796
|
+
amountIn: payment.route.toAmount,
|
|
2797
|
+
fromAddress: account,
|
|
2798
|
+
toAddress: account
|
|
2799
|
+
}) : Promise.resolve([]), new web3Tokens.Token({
|
|
2791
2800
|
blockchain: payment.route.blockchain,
|
|
2792
2801
|
address: web3Constants.CONSTANTS[payment.route.blockchain].USD
|
|
2793
2802
|
}).decimals()]).then(function (_ref2) {
|
|
2794
|
-
var _ref3 = _slicedToArray(_ref2,
|
|
2795
|
-
|
|
2796
|
-
|
|
2803
|
+
var _ref3 = _slicedToArray(_ref2, 3),
|
|
2804
|
+
toTokenUSDExchangeRoutes = _ref3[0],
|
|
2805
|
+
reverseRoutes = _ref3[1],
|
|
2806
|
+
USDDecimals = _ref3[2];
|
|
2807
|
+
|
|
2808
|
+
var toTokenUSDRoute = toTokenUSDExchangeRoutes[0];
|
|
2809
|
+
var reverseRoute = reverseRoutes[0];
|
|
2810
|
+
|
|
2811
|
+
if (reverseRoute) {
|
|
2812
|
+
var reverseAmountOutBN = ethers.ethers.BigNumber.from(reverseRoute.amountOut);
|
|
2813
|
+
var paymentAmountInBN = ethers.ethers.BigNumber.from(payment.route.fromAmount);
|
|
2814
|
+
var divPercent = 100 - reverseAmountOutBN.mul(ethers.ethers.BigNumber.from('100')).div(paymentAmountInBN).abs().toString();
|
|
2815
|
+
|
|
2816
|
+
if (divPercent > 5) {
|
|
2817
|
+
setPaymentValueLoss(divPercent);
|
|
2818
|
+
} else {
|
|
2819
|
+
setPaymentValueLoss(null);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2797
2822
|
|
|
2798
|
-
var
|
|
2799
|
-
var USDAmount;
|
|
2823
|
+
var toTokenUSDAmount;
|
|
2800
2824
|
|
|
2801
2825
|
if (payment.route.toToken.address.toLowerCase() == web3Constants.CONSTANTS[payment.route.blockchain].USD.toLowerCase()) {
|
|
2802
|
-
|
|
2803
|
-
} else if (
|
|
2826
|
+
toTokenUSDAmount = payment.route.toAmount.toString();
|
|
2827
|
+
} else if (toTokenUSDRoute == undefined) {
|
|
2804
2828
|
setPaymentValue('');
|
|
2805
2829
|
return;
|
|
2806
2830
|
} else {
|
|
2807
|
-
|
|
2831
|
+
toTokenUSDAmount = toTokenUSDRoute.amountOut.toString();
|
|
2808
2832
|
}
|
|
2809
2833
|
|
|
2810
|
-
var
|
|
2834
|
+
var toTokenUSDValue = ethers.ethers.utils.formatUnits(toTokenUSDAmount, USDDecimals);
|
|
2811
2835
|
localCurrency.Currency.fromUSD({
|
|
2812
|
-
amount:
|
|
2836
|
+
amount: toTokenUSDValue,
|
|
2813
2837
|
code: currency,
|
|
2814
2838
|
apiKey: apiKey
|
|
2815
2839
|
}).then(setPaymentValue)["catch"](setError);
|
|
@@ -2818,7 +2842,7 @@
|
|
|
2818
2842
|
|
|
2819
2843
|
React.useEffect(function () {
|
|
2820
2844
|
if (account && payment) {
|
|
2821
|
-
|
|
2845
|
+
updatePaymentValue({
|
|
2822
2846
|
updatable: updatable,
|
|
2823
2847
|
payment: payment
|
|
2824
2848
|
});
|
|
@@ -2827,7 +2851,7 @@
|
|
|
2827
2851
|
React.useEffect(function () {
|
|
2828
2852
|
var timeout = setTimeout(function () {
|
|
2829
2853
|
setReloadCount(reloadCount + 1);
|
|
2830
|
-
|
|
2854
|
+
updatePaymentValue({
|
|
2831
2855
|
updatable: updatable
|
|
2832
2856
|
});
|
|
2833
2857
|
}, 15000);
|
|
@@ -2837,7 +2861,8 @@
|
|
|
2837
2861
|
}, [reloadCount, updatable]);
|
|
2838
2862
|
return /*#__PURE__*/React__default["default"].createElement(PaymentValueContext.Provider, {
|
|
2839
2863
|
value: {
|
|
2840
|
-
paymentValue: paymentValue
|
|
2864
|
+
paymentValue: paymentValue,
|
|
2865
|
+
paymentValueLoss: paymentValueLoss
|
|
2841
2866
|
}
|
|
2842
2867
|
}, props.children);
|
|
2843
2868
|
});
|
|
@@ -3271,7 +3296,8 @@
|
|
|
3271
3296
|
approvalTransaction = _useContext4.approvalTransaction;
|
|
3272
3297
|
|
|
3273
3298
|
var _useContext5 = React.useContext(PaymentValueContext),
|
|
3274
|
-
paymentValue = _useContext5.paymentValue
|
|
3299
|
+
paymentValue = _useContext5.paymentValue,
|
|
3300
|
+
paymentValueLoss = _useContext5.paymentValueLoss;
|
|
3275
3301
|
|
|
3276
3302
|
var _useContext6 = React.useContext(reactDialogStack.NavigateStackContext);
|
|
3277
3303
|
_useContext6.navigate;
|
|
@@ -3417,7 +3443,16 @@
|
|
|
3417
3443
|
displayedAmount = "".concat(payment.symbol, " ").concat(payment.amount);
|
|
3418
3444
|
}
|
|
3419
3445
|
|
|
3420
|
-
if (
|
|
3446
|
+
if (paymentValueLoss) {
|
|
3447
|
+
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3448
|
+
className: "PaddingBottomXS"
|
|
3449
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3450
|
+
className: "Alert"
|
|
3451
|
+
}, /*#__PURE__*/React__default["default"].createElement("strong", null, "Payment token would lose ", paymentValueLoss, "% of it's value!"))), /*#__PURE__*/React__default["default"].createElement("button", {
|
|
3452
|
+
className: "ButtonPrimary disabled",
|
|
3453
|
+
onClick: function onClick() {}
|
|
3454
|
+
}, "Pay ", displayedAmount));
|
|
3455
|
+
} else if ((paymentState == 'initialized' || paymentState == 'approving') && payment.route) {
|
|
3421
3456
|
return /*#__PURE__*/React__default["default"].createElement("button", {
|
|
3422
3457
|
className: ["ButtonPrimary", payment.route.approvalRequired && !payment.route.directTransfer ? 'disabled' : ''].join(' '),
|
|
3423
3458
|
onClick: function onClick() {
|
|
@@ -3715,11 +3750,11 @@
|
|
|
3715
3750
|
paymentRoute = _useState6[0],
|
|
3716
3751
|
setPaymentRoute = _useState6[1];
|
|
3717
3752
|
|
|
3718
|
-
var _useState7 = React.useState(track &&
|
|
3753
|
+
var _useState7 = React.useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
|
|
3719
3754
|
_useState8 = _slicedToArray(_useState7, 1),
|
|
3720
3755
|
tracking = _useState8[0];
|
|
3721
3756
|
|
|
3722
|
-
var _useState9 = React.useState(track && track.poll &&
|
|
3757
|
+
var _useState9 = React.useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
|
|
3723
3758
|
_useState10 = _slicedToArray(_useState9, 1),
|
|
3724
3759
|
polling = _useState10[0];
|
|
3725
3760
|
|
|
@@ -3787,7 +3822,6 @@
|
|
|
3787
3822
|
|
|
3788
3823
|
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
3789
3824
|
attempt = parseInt(attempt || 1, 10);
|
|
3790
|
-
console.log('RETRYING PAYMENT TRACKING ATTEMPT ', attempt);
|
|
3791
3825
|
|
|
3792
3826
|
if (attempt < 3) {
|
|
3793
3827
|
setTimeout(function () {
|
|
@@ -3830,9 +3864,7 @@
|
|
|
3830
3864
|
after_block: afterBlock,
|
|
3831
3865
|
to_token: paymentRoute.toToken.address
|
|
3832
3866
|
}).then(function (response) {
|
|
3833
|
-
if (response.status
|
|
3834
|
-
console.log('PAYMENT TRACKING INITIALIZED');
|
|
3835
|
-
} else {
|
|
3867
|
+
if (response.status != 200) {
|
|
3836
3868
|
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
3837
3869
|
}
|
|
3838
3870
|
})["catch"](function (error) {
|
|
@@ -3896,7 +3928,56 @@
|
|
|
3896
3928
|
};
|
|
3897
3929
|
}, [polling, transaction, afterBlock, paymentRoute]);
|
|
3898
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
|
+
|
|
3899
3974
|
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
3975
|
+
storePayment(transaction, afterBlock, paymentRoute, 1);
|
|
3976
|
+
|
|
3977
|
+
if (tracking == false) {
|
|
3978
|
+
return;
|
|
3979
|
+
}
|
|
3980
|
+
|
|
3900
3981
|
setTransaction(transaction);
|
|
3901
3982
|
setAfterBlock(afterBlock);
|
|
3902
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.
|
|
4
|
+
"version": "6.16.2",
|
|
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.
|
|
47
|
-
"@depay/web3-tokens": "^8.0.
|
|
48
|
-
"@depay/web3-wallets": "^9.0.
|
|
46
|
+
"@depay/web3-payments": "^9.3.3",
|
|
47
|
+
"@depay/web3-tokens": "^8.0.1",
|
|
48
|
+
"@depay/web3-wallets": "^9.0.1",
|
|
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.
|
|
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",
|