@ethereansos/interfaces-core 0.4.108 → 0.4.111

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