@ethereansos/interfaces-core 0.4.110 → 0.4.113

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
@@ -48854,103 +48854,83 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
48854
48854
  block = _useState18[0],
48855
48855
  setBlock = _useState18[1];
48856
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
+
48857
48872
  React.useEffect(function () {
48858
48873
  setIpfsHttpClient(ipfsHttpClient.create(context.ipfsHost));
48859
48874
  }, [context]);
48860
-
48861
- function tryUpdateBlock(_x) {
48862
- return _tryUpdateBlock.apply(this, arguments);
48863
- }
48864
-
48865
- function _tryUpdateBlock() {
48866
- _tryUpdateBlock = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(force) {
48867
- var currentBlock, currentBlockNumber;
48868
- 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) {
48869
48879
  while (1) {
48870
- switch (_context2.prev = _context2.next) {
48880
+ switch (_context.prev = _context.next) {
48871
48881
  case 0:
48872
- _context2.prev = 0;
48873
- _context2.next = 3;
48874
- return sendAsync(wallet.ethereum, 'eth_getBlockByNumber', 'latest', true);
48875
-
48876
- case 3:
48877
- currentBlock = _context2.sent;
48878
- currentBlockNumber = parseInt(currentBlock.number);
48879
-
48880
- if (force === true || currentBlockNumber - block >= realBlockInterval) {
48881
- setBlock(currentBlockNumber);
48882
+ if (provider) {
48883
+ _context.next = 2;
48884
+ break;
48882
48885
  }
48883
48886
 
48884
- _context2.next = 10;
48885
- break;
48886
-
48887
- case 8:
48888
- _context2.prev = 8;
48889
- _context2.t0 = _context2["catch"](0);
48890
-
48891
- case 10:
48892
- case "end":
48893
- return _context2.stop();
48894
- }
48895
- }
48896
- }, _callee2, null, [[0, 8]]);
48897
- }));
48898
- return _tryUpdateBlock.apply(this, arguments);
48899
- }
48887
+ return _context.abrupt("return", setter(0));
48900
48888
 
48901
- window.updateAccount = /*#__PURE__*/function () {
48902
- var _updateAccount = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee(acc) {
48903
- return regeneratorRuntime.wrap(function _callee$(_context) {
48904
- while (1) {
48905
- switch (_context.prev = _context.next) {
48906
- case 0:
48907
- delete window.account;
48908
- acc && (window.account = acc);
48889
+ case 2:
48909
48890
  _context.prev = 2;
48910
- _context.t0 = acc && window.ganache;
48891
+ _context.t0 = parseInt;
48892
+ _context.next = 6;
48893
+ return sendAsync(provider, 'eth_blockNumber');
48911
48894
 
48912
- if (!_context.t0) {
48913
- _context.next = 7;
48914
- break;
48915
- }
48895
+ case 6:
48896
+ _context.t1 = _context.sent;
48897
+ currentBlockNumber = (0, _context.t0)(_context.t1);
48916
48898
 
48917
- _context.next = 7;
48918
- return sendAsync(window.ganache, 'evm_addAccount', acc, 0);
48899
+ if (force === true || currentBlockNumber - oldValue >= realBlockInterval) {
48900
+ setter(currentBlockNumber);
48901
+ }
48919
48902
 
48920
- case 7:
48921
- _context.next = 11;
48903
+ _context.next = 13;
48922
48904
  break;
48923
48905
 
48924
- case 9:
48925
- _context.prev = 9;
48926
- _context.t1 = _context["catch"](2);
48927
-
48928
48906
  case 11:
48929
- setBlock(new Date().getTime());
48930
- setTimeout(resetBlockInterval);
48907
+ _context.prev = 11;
48908
+ _context.t2 = _context["catch"](2);
48931
48909
 
48932
48910
  case 13:
48933
48911
  case "end":
48934
48912
  return _context.stop();
48935
48913
  }
48936
48914
  }
48937
- }, _callee, null, [[2, 9]]);
48915
+ }, _callee, null, [[2, 11]]);
48938
48916
  }));
48939
48917
 
48940
- function updateAccount(_x2) {
48941
- return _updateAccount.apply(this, arguments);
48942
- }
48943
-
48944
- return updateAccount;
48945
- }();
48946
-
48947
- function resetBlockInterval() {
48918
+ return function (_x, _x2, _x3, _x4) {
48919
+ return _ref2.apply(this, arguments);
48920
+ };
48921
+ }(), [realBlockInterval]);
48922
+ var resetBlockInterval = React.useCallback(function () {
48948
48923
  intervalId && clearInterval(intervalId);
48949
- wallet && wallet.ethereum && tryUpdateBlock(true);
48950
- wallet && wallet.ethereum && setIntervalId(setInterval(tryUpdateBlock, realBlockIntervalTimeout));
48951
- }
48952
-
48953
- React.useEffect(resetBlockInterval, [realBlockInterval, realBlockIntervalTimeout, wallet && wallet.ethereum]);
48924
+ tryUpdateBlock(wallet === null || wallet === void 0 ? void 0 : wallet.ethereum, block, setBlock, true);
48925
+ tryUpdateBlock(dualProvider, dualBlock, setDualBlock, true);
48926
+ wallet && wallet.ethereum && setIntervalId(setInterval(function () {
48927
+ return tryUpdateBlock(wallet.ethereum, block, setBlock);
48928
+ }, realBlockIntervalTimeout));
48929
+ dualProvider && setIntervalId(setInterval(function () {
48930
+ return tryUpdateBlock(dualProvider, dualBlock, setDualBlock);
48931
+ }, realBlockIntervalTimeout));
48932
+ }, [wallet, dualProvider, realBlockIntervalTimeout, intervalId]);
48933
+ React.useEffect(resetBlockInterval, [realBlockInterval, realBlockIntervalTimeout, wallet && wallet.ethereum, dualProvider]);
48954
48934
  React.useEffect(function () {
48955
48935
  setConnectionStatus(wallet && wallet.ethereum ? CONNECTED : connectionStatus === CONNECTING ? CONNECTING : NOT_CONNECTED);
48956
48936
  setWeb3Instance(wallet && wallet.ethereum && (web3Instance || new Web3__default["default"](wallet.ethereum)) || null);
@@ -48958,7 +48938,11 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
48958
48938
  React.useEffect(function () {
48959
48939
  setContracts({});
48960
48940
  setGlobalContracts(globalContractNames.map(newContractByName));
48961
- setChainId(wallet && wallet.chainId || null);
48941
+ var actualChainId = wallet && wallet.chainId || null;
48942
+ setChainId(actualChainId);
48943
+ var actualDualChainId = actualChainId && context.dualChainId[actualChainId] || null;
48944
+ setDualChainId(actualDualChainId);
48945
+ setDualProvider(actualDualChainId && new Web3__default["default"].providers.HttpProvider(context.chainProvider[actualDualChainId]) || null);
48962
48946
  resetBlockInterval();
48963
48947
  }, [wallet && wallet.chainId]);
48964
48948
 
@@ -49014,6 +48998,53 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49014
48998
  return globalContracts[index];
49015
48999
  };
49016
49000
 
49001
+ window.setAccount = /*#__PURE__*/function () {
49002
+ var _setAccount = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(acc) {
49003
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
49004
+ while (1) {
49005
+ switch (_context2.prev = _context2.next) {
49006
+ case 0:
49007
+ delete window.account;
49008
+ acc && (window.account = acc);
49009
+ _context2.prev = 2;
49010
+ _context2.t0 = acc && window.ganache;
49011
+
49012
+ if (!_context2.t0) {
49013
+ _context2.next = 7;
49014
+ break;
49015
+ }
49016
+
49017
+ _context2.next = 7;
49018
+ return sendAsync(window.ganache, 'evm_addAccount', acc, 0);
49019
+
49020
+ case 7:
49021
+ _context2.next = 11;
49022
+ break;
49023
+
49024
+ case 9:
49025
+ _context2.prev = 9;
49026
+ _context2.t1 = _context2["catch"](2);
49027
+
49028
+ case 11:
49029
+ setBlock(new Date().getTime());
49030
+ setDualBlock(new Date().getTime());
49031
+ setTimeout(resetBlockInterval);
49032
+
49033
+ case 14:
49034
+ case "end":
49035
+ return _context2.stop();
49036
+ }
49037
+ }
49038
+ }, _callee2, null, [[2, 9]]);
49039
+ }));
49040
+
49041
+ function setAccount(_x5) {
49042
+ return _setAccount.apply(this, arguments);
49043
+ }
49044
+
49045
+ return setAccount;
49046
+ }();
49047
+
49017
49048
  var value = _objectSpread2(_objectSpread2({
49018
49049
  connectionStatus: connectionStatus,
49019
49050
  setConnector: setConnector,
@@ -49032,7 +49063,10 @@ var Web3ContextInitializer = function Web3ContextInitializer(_ref) {
49032
49063
  web3: web3Instance,
49033
49064
  block: block,
49034
49065
  getGlobalContract: getGlobalContract,
49035
- newContract: newContract
49066
+ newContract: newContract,
49067
+ dualChainId: dualChainId,
49068
+ dualBlock: dualBlock,
49069
+ dualProvider: dualProvider
49036
49070
  }), wallet && wallet.error && {
49037
49071
  errorMessage: wallet.error.message
49038
49072
  });