@depay/widgets 7.10.0 → 7.13.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/dist/umd/index.js CHANGED
@@ -19227,8 +19227,8 @@
19227
19227
  before = _useContext2.before;
19228
19228
 
19229
19229
  var _useContext3 = React.useContext(PaymentRoutingContext),
19230
- selectedRoute = _useContext3.selectedRoute,
19231
- getPaymentRoutes = _useContext3.getPaymentRoutes;
19230
+ selectedRoute = _useContext3.selectedRoute;
19231
+ _useContext3.getPaymentRoutes;
19232
19232
 
19233
19233
  var _useContext4 = React.useContext(ClosableContext),
19234
19234
  open = _useContext4.open,
@@ -19293,10 +19293,7 @@
19293
19293
  failed(transaction, error);
19294
19294
  }
19295
19295
 
19296
- setPaymentState('initialized');
19297
19296
  setClosable(true);
19298
- setUpdatable(true);
19299
- getPaymentRoutes({});
19300
19297
  navigate('PaymentError');
19301
19298
  };
19302
19299
 
@@ -19596,7 +19593,8 @@
19596
19593
 
19597
19594
  var calculateAmountInWithSlippage = /*#__PURE__*/function () {
19598
19595
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
19599
- var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN;
19596
+ var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN, _difference, _difference2, _slippage, highestAmountBN, _newAmountBN, _readableAmount, _roundedAmountBN;
19597
+
19600
19598
  return regenerator.wrap(function _callee2$(_context2) {
19601
19599
  while (1) {
19602
19600
  switch (_context2.prev = _context2.next) {
@@ -19677,10 +19675,11 @@
19677
19675
 
19678
19676
  case 15:
19679
19677
  if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
19680
- _context2.next = 29;
19678
+ _context2.next = 31;
19681
19679
  break;
19682
19680
  }
19683
19681
 
19682
+ // directional slippage
19684
19683
  difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
19685
19684
  difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
19686
19685
 
@@ -19712,7 +19711,53 @@
19712
19711
  case 28:
19713
19712
  return _context2.abrupt("return", newAmountBN);
19714
19713
 
19715
- case 29:
19714
+ case 31:
19715
+ if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
19716
+ _context2.next = 46;
19717
+ break;
19718
+ }
19719
+
19720
+ // base slippage
19721
+ _difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
19722
+ _difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
19723
+
19724
+ if (_difference.lt(_difference2)) {
19725
+ _slippage = _difference;
19726
+ } else {
19727
+ _slippage = _difference2;
19728
+ }
19729
+
19730
+ if (lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[0].gt(lastAmountsIn[2])) {
19731
+ highestAmountBN = lastAmountsIn[0];
19732
+ } else if (lastAmountsIn[1].gt(lastAmountsIn[2]) && lastAmountsIn[1].gt(lastAmountsIn[0])) {
19733
+ highestAmountBN = lastAmountsIn[1];
19734
+ } else {
19735
+ highestAmountBN = lastAmountsIn[2];
19736
+ }
19737
+
19738
+ _newAmountBN = highestAmountBN.add(_slippage);
19739
+ _context2.next = 39;
19740
+ return route.fromToken.readable(_newAmountBN);
19741
+
19742
+ case 39:
19743
+ _readableAmount = _context2.sent;
19744
+ _context2.next = 42;
19745
+ return route.fromToken.BigNumber(round(_readableAmount));
19746
+
19747
+ case 42:
19748
+ _roundedAmountBN = _context2.sent;
19749
+
19750
+ if (!(route.fromAmount == _roundedAmountBN.toString())) {
19751
+ _context2.next = 45;
19752
+ break;
19753
+ }
19754
+
19755
+ return _context2.abrupt("return");
19756
+
19757
+ case 45:
19758
+ return _context2.abrupt("return", _newAmountBN);
19759
+
19760
+ case 46:
19716
19761
  case "end":
19717
19762
  return _context2.stop();
19718
19763
  }
@@ -20941,8 +20986,8 @@
20941
20986
  });
20942
20987
 
20943
20988
  var PaymentErrorDialog = (function () {
20944
- var _useContext = React.useContext(reactDialogStack.NavigateStackContext),
20945
- navigate = _useContext.navigate;
20989
+ var _useContext = React.useContext(ClosableContext),
20990
+ close = _useContext.close;
20946
20991
 
20947
20992
  var _useContext2 = React.useContext(PaymentContext),
20948
20993
  transaction = _useContext2.transaction;
@@ -20951,7 +20996,7 @@
20951
20996
  recover = _useContext3.recover;
20952
20997
 
20953
20998
  return /*#__PURE__*/React__default["default"].createElement(Dialog$1, {
20954
- stacked: recover ? false : true,
20999
+ stacked: false,
20955
21000
  header: /*#__PURE__*/React__default["default"].createElement("div", {
20956
21001
  className: "PaddingTopS PaddingLeftM PaddingRightM"
20957
21002
  }),
@@ -20982,7 +21027,7 @@
20982
21027
  }, recover == undefined && /*#__PURE__*/React__default["default"].createElement("button", {
20983
21028
  className: "ButtonPrimary",
20984
21029
  onClick: function onClick() {
20985
- return navigate('back');
21030
+ return close();
20986
21031
  }
20987
21032
  }, "Try again"))
20988
21033
  });
@@ -21082,6 +21127,7 @@
21082
21127
 
21083
21128
  var _useContext2 = React.useContext(ConfigurationContext),
21084
21129
  track = _useContext2.track,
21130
+ validated = _useContext2.validated,
21085
21131
  integration = _useContext2.integration,
21086
21132
  link = _useContext2.link,
21087
21133
  type = _useContext2.type;
@@ -21127,6 +21173,9 @@
21127
21173
  var _useContext3 = React.useContext(ClosableContext),
21128
21174
  setClosable = _useContext3.setClosable;
21129
21175
 
21176
+ var _useContext4 = React.useContext(NavigateContext),
21177
+ navigate = _useContext4.navigate;
21178
+
21130
21179
  var openSocket = function openSocket(transaction) {
21131
21180
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
21132
21181
 
@@ -21148,14 +21197,23 @@
21148
21197
  socket.onmessage = function (event) {
21149
21198
  var item = JSON.parse(event.data);
21150
21199
 
21151
- if (item.type === "ping") {
21200
+ if (item.type === "ping" || !item.message) {
21152
21201
  return;
21153
21202
  }
21154
21203
 
21155
- if (item.message && item.message.release) {
21204
+ if (item.message.status == 'failed') {
21205
+ setClosable(true);
21206
+ navigate('PaymentError');
21207
+ }
21208
+
21209
+ if (validated) {
21210
+ validated(item.message.status == 'success');
21211
+ }
21212
+
21213
+ if (item.message.release) {
21214
+ setRelease(true);
21156
21215
  setClosable(!item.message.forward_to);
21157
21216
  setForwardTo(item.message.forward_to);
21158
- setRelease(item.message.release);
21159
21217
  socket.close();
21160
21218
 
21161
21219
  if (!!item.message.forward_to) {
@@ -21217,8 +21275,10 @@
21217
21275
  after_block: afterBlock,
21218
21276
  from_token: paymentRoute.fromToken.address,
21219
21277
  from_amount: paymentRoute.fromAmount.toString(),
21278
+ from_decimals: paymentRoute.fromDecimals,
21220
21279
  to_token: paymentRoute.toToken.address,
21221
21280
  to_amount: paymentRoute.toAmount.toString(),
21281
+ to_decimals: paymentRoute.toDecimals,
21222
21282
  fee_amount: paymentRoute === null || paymentRoute === void 0 ? void 0 : (_paymentRoute$feeAmou = paymentRoute.feeAmount) === null || _paymentRoute$feeAmou === void 0 ? void 0 : _paymentRoute$feeAmou.toString()
21223
21283
  }).then(function (response) {
21224
21284
  if (response.status != 200) {
@@ -21614,12 +21674,12 @@
21614
21674
 
21615
21675
  var Donation = /*#__PURE__*/function () {
21616
21676
  var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(_ref3) {
21617
- var amount, accept, event, sent, confirmed, failed, error, critical, style, blacklist, providers, currency, connected, closed, track, fee, closable, integration, link, container, document, unmount;
21677
+ var amount, accept, event, sent, confirmed, validated, failed, error, critical, style, blacklist, providers, currency, connected, closed, track, fee, closable, integration, link, container, document, unmount;
21618
21678
  return regenerator.wrap(function _callee2$(_context2) {
21619
21679
  while (1) {
21620
21680
  switch (_context2.prev = _context2.next) {
21621
21681
  case 0:
21622
- amount = _ref3.amount, accept = _ref3.accept, event = _ref3.event, sent = _ref3.sent, confirmed = _ref3.confirmed, failed = _ref3.failed, error = _ref3.error, critical = _ref3.critical, style = _ref3.style, blacklist = _ref3.blacklist, providers = _ref3.providers, currency = _ref3.currency, connected = _ref3.connected, closed = _ref3.closed, track = _ref3.track, fee = _ref3.fee, closable = _ref3.closable, integration = _ref3.integration, link = _ref3.link, container = _ref3.container, document = _ref3.document;
21682
+ amount = _ref3.amount, accept = _ref3.accept, event = _ref3.event, sent = _ref3.sent, confirmed = _ref3.confirmed, validated = _ref3.validated, failed = _ref3.failed, error = _ref3.error, critical = _ref3.critical, style = _ref3.style, blacklist = _ref3.blacklist, providers = _ref3.providers, currency = _ref3.currency, connected = _ref3.connected, closed = _ref3.closed, track = _ref3.track, fee = _ref3.fee, closable = _ref3.closable, integration = _ref3.integration, link = _ref3.link, container = _ref3.container, document = _ref3.document;
21623
21683
  requireReactVersion();
21624
21684
  _context2.prev = 2;
21625
21685
  _context2.next = 5;
@@ -21650,6 +21710,7 @@
21650
21710
  fee: fee,
21651
21711
  sent: sent,
21652
21712
  confirmed: confirmed,
21713
+ validated: validated,
21653
21714
  failed: failed,
21654
21715
  blacklist: blacklist,
21655
21716
  providers: providers,
@@ -22133,12 +22194,12 @@
22133
22194
 
22134
22195
  var Payment = /*#__PURE__*/function () {
22135
22196
  var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(_ref3) {
22136
- var accept, amount, event, sent, confirmed, failed, error, critical, style, whitelist, blacklist, providers, currency, connected, closed, track, fee, recover, closable, integration, link, container, before, document, unmount;
22197
+ var accept, amount, event, sent, confirmed, validated, failed, error, critical, style, whitelist, blacklist, providers, currency, connected, closed, track, fee, recover, closable, integration, link, container, before, document, unmount;
22137
22198
  return regenerator.wrap(function _callee2$(_context2) {
22138
22199
  while (1) {
22139
22200
  switch (_context2.prev = _context2.next) {
22140
22201
  case 0:
22141
- accept = _ref3.accept, amount = _ref3.amount, event = _ref3.event, sent = _ref3.sent, confirmed = _ref3.confirmed, failed = _ref3.failed, error = _ref3.error, critical = _ref3.critical, style = _ref3.style, whitelist = _ref3.whitelist, blacklist = _ref3.blacklist, providers = _ref3.providers, currency = _ref3.currency, connected = _ref3.connected, closed = _ref3.closed, track = _ref3.track, fee = _ref3.fee, recover = _ref3.recover, closable = _ref3.closable, integration = _ref3.integration, link = _ref3.link, container = _ref3.container, before = _ref3.before, document = _ref3.document;
22202
+ accept = _ref3.accept, amount = _ref3.amount, event = _ref3.event, sent = _ref3.sent, confirmed = _ref3.confirmed, validated = _ref3.validated, failed = _ref3.failed, error = _ref3.error, critical = _ref3.critical, style = _ref3.style, whitelist = _ref3.whitelist, blacklist = _ref3.blacklist, providers = _ref3.providers, currency = _ref3.currency, connected = _ref3.connected, closed = _ref3.closed, track = _ref3.track, fee = _ref3.fee, recover = _ref3.recover, closable = _ref3.closable, integration = _ref3.integration, link = _ref3.link, container = _ref3.container, before = _ref3.before, document = _ref3.document;
22142
22203
  requireReactVersion();
22143
22204
  _context2.prev = 2;
22144
22205
  _context2.next = 5;
@@ -22169,6 +22230,7 @@
22169
22230
  event: event,
22170
22231
  sent: sent,
22171
22232
  confirmed: confirmed,
22233
+ validated: validated,
22172
22234
  failed: failed,
22173
22235
  whitelist: whitelist,
22174
22236
  blacklist: blacklist,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "7.10.0",
4
+ "version": "7.13.0",
5
5
  "description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
6
6
  "main": "./dist/umd/index.js",
7
7
  "module": "./dist/esm/index.js",