@ethereansos/interfaces-core 0.4.116 → 0.4.119

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/index.cjs.js CHANGED
@@ -48776,6 +48776,7 @@ var useEthosContext = function useEthosContext() {
48776
48776
  return context;
48777
48777
  };
48778
48778
 
48779
+ var abi$8 = new AbiCoder();
48779
48780
  var Web3Context = /*#__PURE__*/React__default["default"].createContext('web3');
48780
48781
  var DEFAULT_BLOCK_INTERVAL = 15;
48781
48782
  var DEFAULT_BLOCK_INTERVAL_TIMEOUT = 40000;
@@ -48919,15 +48920,65 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
48919
48920
  return _ref2.apply(this, arguments);
48920
48921
  };
48921
48922
  }(), [realBlockInterval]);
48923
+ var tryUpdateBlockDual = React.useCallback( /*#__PURE__*/function () {
48924
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(provider, oldValue, setter, force) {
48925
+ var currentBlockNumber;
48926
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
48927
+ while (1) {
48928
+ switch (_context2.prev = _context2.next) {
48929
+ case 0:
48930
+ if (provider) {
48931
+ _context2.next = 2;
48932
+ break;
48933
+ }
48934
+
48935
+ return _context2.abrupt("return", setter(0));
48936
+
48937
+ case 2:
48938
+ _context2.prev = 2;
48939
+ _context2.next = 5;
48940
+ return sendAsync(provider, 'eth_call', {
48941
+ to: '0x4200000000000000000000000000000000000013',
48942
+ data: web3Utils__default["default"].sha3('getL1BlockNumber()').substring(0, 10)
48943
+ });
48944
+
48945
+ case 5:
48946
+ currentBlockNumber = _context2.sent;
48947
+ currentBlockNumber = abi$8.decode(['uint256'], currentBlockNumber)[0].toString();
48948
+ currentBlockNumber = parseInt(currentBlockNumber);
48949
+
48950
+ if (force === true || currentBlockNumber - oldValue >= realBlockInterval) {
48951
+ setter(currentBlockNumber);
48952
+ }
48953
+
48954
+ _context2.next = 13;
48955
+ break;
48956
+
48957
+ case 11:
48958
+ _context2.prev = 11;
48959
+ _context2.t0 = _context2["catch"](2);
48960
+
48961
+ case 13:
48962
+ case "end":
48963
+ return _context2.stop();
48964
+ }
48965
+ }
48966
+ }, _callee2, null, [[2, 11]]);
48967
+ }));
48968
+
48969
+ return function (_x5, _x6, _x7, _x8) {
48970
+ return _ref3.apply(this, arguments);
48971
+ };
48972
+ }(), [realBlockInterval]);
48922
48973
  var resetBlockInterval = React.useCallback(function () {
48923
48974
  intervalId && clearInterval(intervalId);
48924
48975
  tryUpdateBlock(wallet === null || wallet === void 0 ? void 0 : wallet.ethereum, block, setBlock, true);
48925
- tryUpdateBlock(dualProvider, dualBlock, setDualBlock, true);
48976
+ tryUpdateBlockDual(dualProvider && (wallet === null || wallet === void 0 ? void 0 : wallet.ethereum), dualBlock, setDualBlock, true);
48926
48977
 
48927
48978
  if (wallet && wallet.ethereum || dualProvider) {
48928
48979
  setIntervalId(setInterval(function () {
48929
48980
  wallet && wallet.ethereum && tryUpdateBlock(wallet.ethereum, block, setBlock);
48930
- dualProvider && tryUpdateBlock(dualProvider, dualBlock, setDualBlock);
48981
+ dualProvider && wallet && wallet.ethereum && tryUpdateBlockDual(wallet.ethereum, dualBlock, setDualBlock);
48931
48982
  }, realBlockIntervalTimeout));
48932
48983
  }
48933
48984
  }, [wallet, dualProvider, realBlockIntervalTimeout, intervalId]);
@@ -49000,31 +49051,31 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49000
49051
  };
49001
49052
 
49002
49053
  window.setAccount = /*#__PURE__*/function () {
49003
- var _setAccount = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(acc) {
49004
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
49054
+ var _setAccount = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(acc) {
49055
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
49005
49056
  while (1) {
49006
- switch (_context2.prev = _context2.next) {
49057
+ switch (_context3.prev = _context3.next) {
49007
49058
  case 0:
49008
49059
  delete window.account;
49009
49060
  acc && (window.account = acc);
49010
- _context2.prev = 2;
49011
- _context2.t0 = acc && window.ganache;
49061
+ _context3.prev = 2;
49062
+ _context3.t0 = acc && window.ganache;
49012
49063
 
49013
- if (!_context2.t0) {
49014
- _context2.next = 7;
49064
+ if (!_context3.t0) {
49065
+ _context3.next = 7;
49015
49066
  break;
49016
49067
  }
49017
49068
 
49018
- _context2.next = 7;
49069
+ _context3.next = 7;
49019
49070
  return sendAsync(window.ganache, 'evm_addAccount', acc, 0);
49020
49071
 
49021
49072
  case 7:
49022
- _context2.next = 11;
49073
+ _context3.next = 11;
49023
49074
  break;
49024
49075
 
49025
49076
  case 9:
49026
- _context2.prev = 9;
49027
- _context2.t1 = _context2["catch"](2);
49077
+ _context3.prev = 9;
49078
+ _context3.t1 = _context3["catch"](2);
49028
49079
 
49029
49080
  case 11:
49030
49081
  setBlock(new Date().getTime());
@@ -49033,13 +49084,13 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49033
49084
 
49034
49085
  case 14:
49035
49086
  case "end":
49036
- return _context2.stop();
49087
+ return _context3.stop();
49037
49088
  }
49038
49089
  }
49039
- }, _callee2, null, [[2, 9]]);
49090
+ }, _callee3, null, [[2, 9]]);
49040
49091
  }));
49041
49092
 
49042
- function setAccount(_x5) {
49093
+ function setAccount(_x9) {
49043
49094
  return _setAccount.apply(this, arguments);
49044
49095
  }
49045
49096
 
@@ -64428,12 +64479,12 @@ function getTokenPricesInDollarsOnCoingecko(_x4, _x5) {
64428
64479
  }
64429
64480
 
64430
64481
  function _getTokenPricesInDollarsOnCoingecko() {
64431
- _getTokenPricesInDollarsOnCoingecko = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(_ref2, t) {
64482
+ _getTokenPricesInDollarsOnCoingecko = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(_ref2, t) {
64432
64483
  var context, web3Data, tokens, response, tkns, _iterator2, _step2, token, prom, _i, _tkns, _i2, _tkns2, _iterator3, _step3;
64433
64484
 
64434
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
64485
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
64435
64486
  while (1) {
64436
- switch (_context3.prev = _context3.next) {
64487
+ switch (_context4.prev = _context4.next) {
64437
64488
  case 0:
64438
64489
  context = _ref2.context, web3Data = _ref2.web3Data;
64439
64490
  tokens = (!(t instanceof Array) ? t = t.split(',') : t).map(function (it) {
@@ -64444,139 +64495,164 @@ function _getTokenPricesInDollarsOnCoingecko() {
64444
64495
  };
64445
64496
  tkns = [];
64446
64497
  _iterator2 = _createForOfIteratorHelper(tokens);
64447
- _context3.prev = 5;
64498
+ _context4.prev = 5;
64448
64499
 
64449
64500
  _iterator2.s();
64450
64501
 
64451
64502
  case 7:
64452
64503
  if ((_step2 = _iterator2.n()).done) {
64453
- _context3.next = 29;
64504
+ _context4.next = 29;
64454
64505
  break;
64455
64506
  }
64456
64507
 
64457
64508
  token = _step2.value;
64458
64509
 
64459
64510
  if (!(!token || token === VOID_ETHEREUM_ADDRESS)) {
64460
- _context3.next = 14;
64511
+ _context4.next = 14;
64461
64512
  break;
64462
64513
  }
64463
64514
 
64464
- _context3.next = 12;
64515
+ _context4.next = 12;
64465
64516
  return getEthereumPrice({
64466
64517
  context: context
64467
64518
  });
64468
64519
 
64469
64520
  case 12:
64470
- response.data[token] = _context3.sent;
64471
- return _context3.abrupt("continue", 27);
64521
+ response.data[token] = _context4.sent;
64522
+ return _context4.abrupt("continue", 27);
64472
64523
 
64473
64524
  case 14:
64474
64525
  if (!(tokenPrices[token] && tokenPrices[token].requestExpires > new Date().getTime() && tokenPrices[token].price !== 0)) {
64475
- _context3.next = 18;
64526
+ _context4.next = 18;
64476
64527
  break;
64477
64528
  }
64478
64529
 
64479
64530
  response.data[token] = {
64480
64531
  usd: tokenPrices[token].price
64481
64532
  };
64482
- _context3.next = 27;
64533
+ _context4.next = 27;
64483
64534
  break;
64484
64535
 
64485
64536
  case 18:
64486
64537
  if (!tokenPricesPromises[token]) {
64487
- _context3.next = 26;
64538
+ _context4.next = 26;
64488
64539
  break;
64489
64540
  }
64490
64541
 
64491
- _context3.next = 21;
64542
+ _context4.next = 21;
64492
64543
  return tokenPricesPromises[token];
64493
64544
 
64494
64545
  case 21:
64495
- _context3.t0 = token;
64496
- _context3.t1 = _context3.sent.data[_context3.t0].usd;
64546
+ _context4.t0 = token;
64547
+ _context4.t1 = _context4.sent.data[_context4.t0].usd;
64497
64548
  response.data[token] = {
64498
- usd: _context3.t1
64549
+ usd: _context4.t1
64499
64550
  };
64500
- _context3.next = 27;
64551
+ _context4.next = 27;
64501
64552
  break;
64502
64553
 
64503
64554
  case 26:
64504
64555
  tkns.push(token);
64505
64556
 
64506
64557
  case 27:
64507
- _context3.next = 7;
64558
+ _context4.next = 7;
64508
64559
  break;
64509
64560
 
64510
64561
  case 29:
64511
- _context3.next = 34;
64562
+ _context4.next = 34;
64512
64563
  break;
64513
64564
 
64514
64565
  case 31:
64515
- _context3.prev = 31;
64516
- _context3.t2 = _context3["catch"](5);
64566
+ _context4.prev = 31;
64567
+ _context4.t2 = _context4["catch"](5);
64517
64568
 
64518
- _iterator2.e(_context3.t2);
64569
+ _iterator2.e(_context4.t2);
64519
64570
 
64520
64571
  case 34:
64521
- _context3.prev = 34;
64572
+ _context4.prev = 34;
64522
64573
 
64523
64574
  _iterator2.f();
64524
64575
 
64525
- return _context3.finish(34);
64576
+ return _context4.finish(34);
64526
64577
 
64527
64578
  case 37:
64528
64579
  prom = /*#__PURE__*/function () {
64529
- var _ref3 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(t1, t2) {
64580
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(t1, t2) {
64530
64581
  var res;
64531
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
64582
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
64532
64583
  while (1) {
64533
- switch (_context2.prev = _context2.next) {
64584
+ switch (_context3.prev = _context3.next) {
64534
64585
  case 0:
64535
64586
  res = {
64536
64587
  data: {}
64537
64588
  };
64538
- _context2.prev = 1;
64539
- _context2.t0 = t1.length > 0;
64589
+ _context3.prev = 1;
64590
+ _context3.t0 = t1.length > 0;
64540
64591
 
64541
- if (!_context2.t0) {
64542
- _context2.next = 9;
64592
+ if (!_context3.t0) {
64593
+ _context3.next = 7;
64543
64594
  break;
64544
64595
  }
64545
64596
 
64546
- _context2.next = 6;
64547
- return fetch(context.coingeckoCoinPriceURL + t1.join(','));
64597
+ _context3.next = 6;
64598
+ return Promise.all(context.coingeckoCoinPriceURLTemplates.map( /*#__PURE__*/function () {
64599
+ var _ref4 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(it) {
64600
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
64601
+ while (1) {
64602
+ switch (_context2.prev = _context2.next) {
64603
+ case 0:
64604
+ _context2.next = 2;
64605
+ return fetch(it + t1.join(','));
64606
+
64607
+ case 2:
64608
+ _context2.next = 4;
64609
+ return _context2.sent.json();
64610
+
64611
+ case 4:
64612
+ return _context2.abrupt("return", _context2.sent);
64613
+
64614
+ case 5:
64615
+ case "end":
64616
+ return _context2.stop();
64617
+ }
64618
+ }
64619
+ }, _callee2);
64620
+ }));
64621
+
64622
+ return function (_x8) {
64623
+ return _ref4.apply(this, arguments);
64624
+ };
64625
+ }()));
64548
64626
 
64549
64627
  case 6:
64550
- _context2.next = 8;
64551
- return _context2.sent.json();
64628
+ res.data = _context3.sent.reduce(function (acc, it) {
64629
+ return _objectSpread2(_objectSpread2({}, acc), it);
64630
+ }, {});
64552
64631
 
64553
- case 8:
64554
- res.data = _context2.sent;
64632
+ case 7:
64633
+ _context3.next = 11;
64634
+ break;
64555
64635
 
64556
64636
  case 9:
64557
- _context2.next = 13;
64558
- break;
64637
+ _context3.prev = 9;
64638
+ _context3.t1 = _context3["catch"](1);
64559
64639
 
64560
64640
  case 11:
64561
- _context2.prev = 11;
64562
- _context2.t1 = _context2["catch"](1);
64563
-
64564
- case 13:
64565
- _context2.next = 15;
64641
+ _context3.next = 13;
64566
64642
  return elaboratePrices({
64567
64643
  context: context,
64568
64644
  web3Data: web3Data
64569
64645
  }, res, t2);
64570
64646
 
64571
- case 15:
64572
- return _context2.abrupt("return", _context2.sent);
64647
+ case 13:
64648
+ return _context3.abrupt("return", _context3.sent);
64573
64649
 
64574
- case 16:
64650
+ case 14:
64575
64651
  case "end":
64576
- return _context2.stop();
64652
+ return _context3.stop();
64577
64653
  }
64578
64654
  }
64579
- }, _callee2, null, [[1, 11]]);
64655
+ }, _callee3, null, [[1, 9]]);
64580
64656
  }));
64581
64657
 
64582
64658
  return function prom(_x6, _x7) {
@@ -64591,11 +64667,11 @@ function _getTokenPricesInDollarsOnCoingecko() {
64591
64667
  tokenPricesPromises[token] = prom;
64592
64668
  }
64593
64669
 
64594
- _context3.next = 42;
64670
+ _context4.next = 42;
64595
64671
  return prom;
64596
64672
 
64597
64673
  case 42:
64598
- prom = _context3.sent;
64674
+ prom = _context4.sent;
64599
64675
  Object.entries(prom.data).forEach(function (it) {
64600
64676
  return response.data[it[0]] = it[1];
64601
64677
  });
@@ -64621,14 +64697,14 @@ function _getTokenPricesInDollarsOnCoingecko() {
64621
64697
  _iterator3.f();
64622
64698
  }
64623
64699
 
64624
- return _context3.abrupt("return", response);
64700
+ return _context4.abrupt("return", response);
64625
64701
 
64626
64702
  case 48:
64627
64703
  case "end":
64628
- return _context3.stop();
64704
+ return _context4.stop();
64629
64705
  }
64630
64706
  }
64631
- }, _callee3, null, [[5, 31, 34, 37]]);
64707
+ }, _callee4, null, [[5, 31, 34, 37]]);
64632
64708
  }));
64633
64709
  return _getTokenPricesInDollarsOnCoingecko.apply(this, arguments);
64634
64710
  }