@ethereansos/interfaces-core 0.4.109 → 0.4.112

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
@@ -48779,51 +48779,6 @@ var useEthosContext = function useEthosContext() {
48779
48779
  var Web3Context = /*#__PURE__*/React__default["default"].createContext('web3');
48780
48780
  var DEFAULT_BLOCK_INTERVAL = 15;
48781
48781
  var DEFAULT_BLOCK_INTERVAL_TIMEOUT = 40000;
48782
-
48783
- var chains = require('use-wallet').chains;
48784
- /**
48785
- * WRAP CHAINS START
48786
- **/
48787
-
48788
-
48789
- var ETH = chains.getChainInformation(1).nativeCurrency;
48790
- var WRAPPED_CHAINS = {
48791
- 10: {
48792
- id: 10,
48793
- nativeCurrency: ETH,
48794
- type: 'main',
48795
- fullName: 'Optimism Mainnet',
48796
- shortName: 'Optimism',
48797
- explorerUrl: 'https://optimistic.etherscan.io',
48798
- testnet: false
48799
- }
48800
- };
48801
-
48802
- function wrap(methodName, funct, force) {
48803
- var oldFunction = chains[methodName];
48804
-
48805
- chains[methodName] = function (chainId) {
48806
- var args = [].concat(Array.prototype.slice.call(arguments), [oldFunction]);
48807
- return (WRAPPED_CHAINS[parseInt(chainId)] || force ? funct : oldFunction).apply(chains, args);
48808
- };
48809
- }
48810
-
48811
- wrap('isKnownChain', function () {
48812
- return true;
48813
- });
48814
- wrap('getChainInformation', function (chainId) {
48815
- return WRAPPED_CHAINS[parseInt(chainId)];
48816
- });
48817
- wrap('getKnownChainsIds', function (oldFunction) {
48818
- return [].concat(_toConsumableArray(oldFunction()), _toConsumableArray(Object.keys(WRAPPED_CHAINS)));
48819
- });
48820
- wrap('getKnownChainInformation', function (oldFunction) {
48821
- return [].concat(_toConsumableArray(oldFunction()), _toConsumableArray(Object.values(WRAPPED_CHAINS)));
48822
- });
48823
- /**
48824
- * WRAP CHAINS END
48825
- **/
48826
-
48827
48782
  var web3States = {
48828
48783
  NOT_CONNECTED: NOT_CONNECTED,
48829
48784
  CONNECTED: CONNECTED,
@@ -48899,103 +48854,79 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
48899
48854
  block = _useState18[0],
48900
48855
  setBlock = _useState18[1];
48901
48856
 
48857
+ var _useState19 = React.useState(null),
48858
+ _useState20 = _slicedToArray(_useState19, 2),
48859
+ dualChainId = _useState20[0],
48860
+ setDualChainId = _useState20[1];
48861
+
48862
+ var _useState21 = React.useState(0),
48863
+ _useState22 = _slicedToArray(_useState21, 2),
48864
+ dualBlock = _useState22[0],
48865
+ setDualBlock = _useState22[1];
48866
+
48867
+ var _useState23 = React.useState(null),
48868
+ _useState24 = _slicedToArray(_useState23, 2),
48869
+ dualProvider = _useState24[0],
48870
+ setDualProvider = _useState24[1];
48871
+
48902
48872
  React.useEffect(function () {
48903
48873
  setIpfsHttpClient(ipfsHttpClient.create(context.ipfsHost));
48904
48874
  }, [context]);
48905
-
48906
- function tryUpdateBlock(_x) {
48907
- return _tryUpdateBlock.apply(this, arguments);
48908
- }
48909
-
48910
- function _tryUpdateBlock() {
48911
- _tryUpdateBlock = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(force) {
48912
- var currentBlock, currentBlockNumber;
48913
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
48875
+ var tryUpdateBlock = React.useCallback( /*#__PURE__*/function () {
48876
+ var _ref2 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee(provider, oldValue, setter, force) {
48877
+ var currentBlockNumber;
48878
+ return regeneratorRuntime.wrap(function _callee$(_context) {
48914
48879
  while (1) {
48915
- switch (_context2.prev = _context2.next) {
48880
+ switch (_context.prev = _context.next) {
48916
48881
  case 0:
48917
- _context2.prev = 0;
48918
- _context2.next = 3;
48919
- return sendAsync(wallet.ethereum, 'eth_getBlockByNumber', 'latest', true);
48920
-
48921
- case 3:
48922
- currentBlock = _context2.sent;
48923
- currentBlockNumber = parseInt(currentBlock.number);
48924
-
48925
- if (force === true || currentBlockNumber - block >= realBlockInterval) {
48926
- setBlock(currentBlockNumber);
48882
+ if (!provider) {
48883
+ setter(0);
48927
48884
  }
48928
48885
 
48929
- _context2.next = 10;
48930
- break;
48931
-
48932
- case 8:
48933
- _context2.prev = 8;
48934
- _context2.t0 = _context2["catch"](0);
48935
-
48936
- case 10:
48937
- case "end":
48938
- return _context2.stop();
48939
- }
48940
- }
48941
- }, _callee2, null, [[0, 8]]);
48942
- }));
48943
- return _tryUpdateBlock.apply(this, arguments);
48944
- }
48886
+ _context.prev = 1;
48887
+ _context.t0 = parseInt;
48888
+ _context.next = 5;
48889
+ return sendAsync(provider, 'eth_blockNumber');
48945
48890
 
48946
- window.updateAccount = /*#__PURE__*/function () {
48947
- var _updateAccount = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee(acc) {
48948
- return regeneratorRuntime.wrap(function _callee$(_context) {
48949
- while (1) {
48950
- switch (_context.prev = _context.next) {
48951
- case 0:
48952
- delete window.account;
48953
- acc && (window.account = acc);
48954
- _context.prev = 2;
48955
- _context.t0 = acc && window.ganache;
48891
+ case 5:
48892
+ _context.t1 = _context.sent;
48893
+ currentBlockNumber = (0, _context.t0)(_context.t1);
48956
48894
 
48957
- if (!_context.t0) {
48958
- _context.next = 7;
48959
- break;
48895
+ if (force === true || currentBlockNumber - oldValue >= realBlockInterval) {
48896
+ setter(currentBlockNumber);
48960
48897
  }
48961
48898
 
48962
- _context.next = 7;
48963
- return sendAsync(window.ganache, 'evm_addAccount', acc, 0);
48964
-
48965
- case 7:
48966
- _context.next = 11;
48899
+ _context.next = 12;
48967
48900
  break;
48968
48901
 
48969
- case 9:
48970
- _context.prev = 9;
48971
- _context.t1 = _context["catch"](2);
48972
-
48973
- case 11:
48974
- setBlock(new Date().getTime());
48975
- setTimeout(resetBlockInterval);
48902
+ case 10:
48903
+ _context.prev = 10;
48904
+ _context.t2 = _context["catch"](1);
48976
48905
 
48977
- case 13:
48906
+ case 12:
48978
48907
  case "end":
48979
48908
  return _context.stop();
48980
48909
  }
48981
48910
  }
48982
- }, _callee, null, [[2, 9]]);
48911
+ }, _callee, null, [[1, 10]]);
48983
48912
  }));
48984
48913
 
48985
- function updateAccount(_x2) {
48986
- return _updateAccount.apply(this, arguments);
48987
- }
48988
-
48989
- return updateAccount;
48990
- }();
48991
-
48992
- function resetBlockInterval() {
48914
+ return function (_x, _x2, _x3, _x4) {
48915
+ return _ref2.apply(this, arguments);
48916
+ };
48917
+ }(), [realBlockInterval]);
48918
+ var resetBlockInterval = React.useCallback(function () {
48993
48919
  intervalId && clearInterval(intervalId);
48994
- wallet && wallet.ethereum && tryUpdateBlock(true);
48995
- wallet && wallet.ethereum && setIntervalId(setInterval(tryUpdateBlock, realBlockIntervalTimeout));
48996
- }
48997
-
48998
- React.useEffect(resetBlockInterval, [realBlockInterval, realBlockIntervalTimeout, wallet && wallet.ethereum]);
48920
+ tryUpdateBlock(wallet === null || wallet === void 0 ? void 0 : wallet.ethereum, block, setBlock, true);
48921
+ tryUpdateBlock(dualProvider, dualBlock, setDualBlock, true);
48922
+ wallet && wallet.ethereum && setIntervalId(setInterval(function () {
48923
+ return tryUpdateBlock(wallet.ethereum, block, setBlock);
48924
+ }, realBlockIntervalTimeout));
48925
+ dualProvider && setIntervalId(setInterval(function () {
48926
+ return tryUpdateBlock(dualProvider, dualBlock, setDualBlock);
48927
+ }, realBlockIntervalTimeout));
48928
+ }, [wallet, dualProvider, realBlockIntervalTimeout, intervalId]);
48929
+ React.useEffect(resetBlockInterval, [realBlockInterval, realBlockIntervalTimeout, wallet && wallet.ethereum, dualProvider]);
48999
48930
  React.useEffect(function () {
49000
48931
  setConnectionStatus(wallet && wallet.ethereum ? CONNECTED : connectionStatus === CONNECTING ? CONNECTING : NOT_CONNECTED);
49001
48932
  setWeb3Instance(wallet && wallet.ethereum && (web3Instance || new Web3__default["default"](wallet.ethereum)) || null);
@@ -49003,7 +48934,11 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49003
48934
  React.useEffect(function () {
49004
48935
  setContracts({});
49005
48936
  setGlobalContracts(globalContractNames.map(newContractByName));
49006
- setChainId(wallet && wallet.chainId || null);
48937
+ var actualChainId = wallet && wallet.chainId || null;
48938
+ setChainId(actualChainId);
48939
+ var actualDualChainId = actualChainId && context.dualChainId[actualChainId] || null;
48940
+ setDualChainId(actualDualChainId);
48941
+ setDualProvider(actualDualChainId && new Web3__default["default"].providers.HttpProvider(context.chainProvider[actualDualChainId]) || null);
49007
48942
  resetBlockInterval();
49008
48943
  }, [wallet && wallet.chainId]);
49009
48944
 
@@ -49059,6 +48994,53 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49059
48994
  return globalContracts[index];
49060
48995
  };
49061
48996
 
48997
+ window.setAccount = /*#__PURE__*/function () {
48998
+ var _setAccount = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(acc) {
48999
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
49000
+ while (1) {
49001
+ switch (_context2.prev = _context2.next) {
49002
+ case 0:
49003
+ delete window.account;
49004
+ acc && (window.account = acc);
49005
+ _context2.prev = 2;
49006
+ _context2.t0 = acc && window.ganache;
49007
+
49008
+ if (!_context2.t0) {
49009
+ _context2.next = 7;
49010
+ break;
49011
+ }
49012
+
49013
+ _context2.next = 7;
49014
+ return sendAsync(window.ganache, 'evm_addAccount', acc, 0);
49015
+
49016
+ case 7:
49017
+ _context2.next = 11;
49018
+ break;
49019
+
49020
+ case 9:
49021
+ _context2.prev = 9;
49022
+ _context2.t1 = _context2["catch"](2);
49023
+
49024
+ case 11:
49025
+ setBlock(new Date().getTime());
49026
+ setDualBlock(new Date().getTime());
49027
+ setTimeout(resetBlockInterval);
49028
+
49029
+ case 14:
49030
+ case "end":
49031
+ return _context2.stop();
49032
+ }
49033
+ }
49034
+ }, _callee2, null, [[2, 9]]);
49035
+ }));
49036
+
49037
+ function setAccount(_x5) {
49038
+ return _setAccount.apply(this, arguments);
49039
+ }
49040
+
49041
+ return setAccount;
49042
+ }();
49043
+
49062
49044
  var value = _objectSpread2(_objectSpread2({
49063
49045
  connectionStatus: connectionStatus,
49064
49046
  setConnector: setConnector,
@@ -49077,7 +49059,10 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49077
49059
  web3: web3Instance,
49078
49060
  block: block,
49079
49061
  getGlobalContract: getGlobalContract,
49080
- newContract: newContract
49062
+ newContract: newContract,
49063
+ dualChainId: dualChainId,
49064
+ dualBlock: dualBlock,
49065
+ dualProvider: dualProvider
49081
49066
  }), wallet && wallet.error && {
49082
49067
  errorMessage: wallet.error.message
49083
49068
  });