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