From d6340688c0fc1709625d5c05bac0f8d7c7a622c0 Mon Sep 17 00:00:00 2001 From: reasje Date: Fri, 16 Feb 2024 19:29:40 +0330 Subject: [PATCH 1/3] refactor: hide wifi hooks --- .../dapp_hooks/dapp_hooks_page.dart | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart index 7df89aa1..b81ff715 100644 --- a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart +++ b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart @@ -87,30 +87,30 @@ class DAppHooksPage extends HookConsumerWidget { padding: const EdgeInsets.symmetric(horizontal: Sizes.spaceXLarge), child: Column( children: [ - MXCSwitchRowItem( - key: const Key('wifiHookSwitch'), - title: translate('wifi_hooks'), - value: dappHooksState.dAppHooksData!.wifiHooks.enabled, - onChanged: dappHooksPresenter.enableWifiHooks, - enabled: isSettingsChangeEnabled, - textTrailingWidget: MXCInformationButton(texts: [ - TextSpan( - text: FlutterI18n.translate(context, 'experiencing_issues'), - style: FontTheme.of(context) - .subtitle2() - .copyWith(color: ColorsTheme.of(context).chipTextBlack), - ), - const TextSpan(text: ' '), - TextSpan( - text: - FlutterI18n.translate(context, 'wifi_hooks_solutions'), - style: FontTheme.of(context) - .subtitle1() - .copyWith(color: ColorsTheme.of(context).chipTextBlack), - ), - ]), - ), - const SizedBox(height: Sizes.spaceNormal), + // MXCSwitchRowItem( + // key: const Key('wifiHookSwitch'), + // title: translate('wifi_hooks'), + // value: dappHooksState.dAppHooksData!.wifiHooks.enabled, + // onChanged: dappHooksPresenter.enableWifiHooks, + // enabled: isSettingsChangeEnabled, + // textTrailingWidget: MXCInformationButton(texts: [ + // TextSpan( + // text: FlutterI18n.translate(context, 'experiencing_issues'), + // style: FontTheme.of(context) + // .subtitle2() + // .copyWith(color: ColorsTheme.of(context).chipTextBlack), + // ), + // const TextSpan(text: ' '), + // TextSpan( + // text: + // FlutterI18n.translate(context, 'wifi_hooks_solutions'), + // style: FontTheme.of(context) + // .subtitle1() + // .copyWith(color: ColorsTheme.of(context).chipTextBlack), + // ), + // ]), + // ), + // const SizedBox(height: Sizes.spaceNormal), MXCSwitchRowItem( key: const Key('minerHookSwitch'), title: translate('miner_hooks'), From cc9ca9fb5de6e97efb66038461d40d093f97a7de Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 26 Feb 2024 18:51:48 +0330 Subject: [PATCH 2/3] refactor: mep2542 contract update --- .../ens_dart/lib/src/contracts/contracts.dart | 2 +- .../{mep_2542.g.dart => mep2542.g.dart} | 268 +++++++++++++++--- 2 files changed, 229 insertions(+), 41 deletions(-) rename packages/ens_dart/lib/src/contracts/{mep_2542.g.dart => mep2542.g.dart} (58%) diff --git a/packages/ens_dart/lib/src/contracts/contracts.dart b/packages/ens_dart/lib/src/contracts/contracts.dart index 2ad30319..f0431d7e 100644 --- a/packages/ens_dart/lib/src/contracts/contracts.dart +++ b/packages/ens_dart/lib/src/contracts/contracts.dart @@ -10,6 +10,6 @@ export 'ens_registry_fallback.g.dart' export 'ens_nft.g.dart' hide Approval, Transfer, ApprovalForAll; export 'router_contract.g.dart'; export 'erc_6551_account_impl.g.dart'; -export 'mep_2542.g.dart' +export 'mep2542.g.dart' hide Initialized, OwnershipTransferred, ControllerChanged; export 'erc_6551_registry.g.dart'; diff --git a/packages/ens_dart/lib/src/contracts/mep_2542.g.dart b/packages/ens_dart/lib/src/contracts/mep2542.g.dart similarity index 58% rename from packages/ens_dart/lib/src/contracts/mep_2542.g.dart rename to packages/ens_dart/lib/src/contracts/mep2542.g.dart index 660eb1db..4cd2c21e 100644 --- a/packages/ens_dart/lib/src/contracts/mep_2542.g.dart +++ b/packages/ens_dart/lib/src/contracts/mep2542.g.dart @@ -5,7 +5,7 @@ import 'package:web3dart/web3dart.dart' as _i1; import 'dart:typed_data' as _i2; final _contractAbi = _i1.ContractAbi.fromJson( - '[{"inputs":[],"name":"AlreadyClaim","type":"error"},{"inputs":[{"internalType":"uint256","name":"_size","type":"uint256"},{"internalType":"uint256","name":"_start","type":"uint256"},{"internalType":"uint256","name":"_end","type":"uint256"}],"name":"InvalidCodeAtRange","type":"error"},{"inputs":[],"name":"InvalidEpochNumber","type":"error"},{"inputs":[],"name":"InvalidLength","type":"error"},{"inputs":[],"name":"InvalidProof","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidTokenOwnership","type":"error"},{"inputs":[],"name":"RewardExpired","type":"error"},{"inputs":[],"name":"SensorBalanceRequired","type":"error"},{"inputs":[],"name":"TokenExceeds","type":"error"},{"inputs":[],"name":"TokenExist","type":"error"},{"inputs":[],"name":"TokenNotFound","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"WriteError","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"miner","type":"address"},{"indexed":true,"internalType":"uint256","name":"epochNumber","type":"uint256"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"indexed":false,"internalType":"struct MEP2542.RewardInfo","name":"rewardInfo","type":"tuple"}],"name":"ClaimedReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"},{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"ControllerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epochNumber","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"rewardMerkleRoot","type":"bytes32"},{"indexed":false,"internalType":"address","name":"onlineStatusPointer","type":"address"}],"name":"ReleaseEpoch","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ERC6551AccountImplAddr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ERC6551Registry","outputs":[{"internalType":"contract IERC6551Registry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MEP1004Token_","outputs":[{"internalType":"contract MEP1004Token","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"__Controllable_init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"bytes32[]","name":"proofs","type":"bytes32[]"}],"internalType":"struct MEP2542.ProofArray[]","name":"proofs","type":"tuple[]"},{"internalType":"uint256[]","name":"epochIds","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"internalType":"struct MEP2542.RewardInfo[]","name":"rewards","type":"tuple[]"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"controllers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochExpiredTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"epochReleaseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"internalType":"uint256[]","name":"epochNumbers","type":"uint256[]"}],"name":"getMinerClaimedEpochs","outputs":[{"internalType":"bool[]","name":"","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochNumber","type":"uint256"},{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"}],"name":"getMinerOnlineStatus","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardTokenInfo","outputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"internalType":"struct MEP2542.RewardTokenInfo[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getUserSelectedToken","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"address","name":"_ERC6551Registry","type":"address"},{"internalType":"address","name":"_ERC6551AccountImplAddr","type":"address"},{"internalType":"address","name":"_MEP1004Addr","type":"address"},{"internalType":"address","name":"_sensorToken","type":"address"},{"internalType":"uint256","name":"_epochExpiredTime","type":"uint256"},{"internalType":"uint256","name":"_maxSelectToken","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxSelectToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochNumber","type":"uint256"},{"internalType":"bytes32","name":"rewardMerkleRoot","type":"bytes32"},{"internalType":"bytes","name":"statusBitMap","type":"bytes"}],"name":"releaseEpoch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"removeRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardMerkleRoots","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardTokens","outputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"selectToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sensorToken","outputs":[{"internalType":"contract SensorToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxSelectToken","type":"uint256"}],"name":"setMaxSelectToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"name":"setRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]', + '[{"inputs":[],"name":"AlreadyClaim","type":"error"},{"inputs":[{"internalType":"uint256","name":"_size","type":"uint256"},{"internalType":"uint256","name":"_start","type":"uint256"},{"internalType":"uint256","name":"_end","type":"uint256"}],"name":"InvalidCodeAtRange","type":"error"},{"inputs":[],"name":"InvalidEpochNumber","type":"error"},{"inputs":[],"name":"InvalidLength","type":"error"},{"inputs":[],"name":"InvalidOrder","type":"error"},{"inputs":[],"name":"InvalidProof","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidTokenOwnership","type":"error"},{"inputs":[],"name":"RewardExpired","type":"error"},{"inputs":[],"name":"SensorBalanceRequired","type":"error"},{"inputs":[],"name":"TokenExceeds","type":"error"},{"inputs":[],"name":"TokenExist","type":"error"},{"inputs":[],"name":"TokenNotFound","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"WriteError","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"miner","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"epochIds","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"indexed":false,"internalType":"struct MEP2542.RewardInfo[]","name":"rewardInfos","type":"tuple[]"}],"name":"BulkClaimedReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"miner","type":"address"},{"indexed":true,"internalType":"uint256","name":"epochNumber","type":"uint256"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"indexed":false,"internalType":"struct MEP2542.RewardInfo","name":"rewardInfo","type":"tuple"}],"name":"ClaimedReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"},{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"ControllerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epochNumber","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"rewardMerkleRoot","type":"bytes32"},{"indexed":false,"internalType":"address","name":"onlineStatusPointer","type":"address"}],"name":"ReleaseEpoch","type":"event"},{"inputs":[],"name":"CLAIM_PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ERC6551AccountImplAddr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ERC6551Registry","outputs":[{"internalType":"contract IERC6551Registry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MEP1004Token_","outputs":[{"internalType":"contract MEP1004Token","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"__Controllable_init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"bytes32[]","name":"proofs","type":"bytes32[]"}],"internalType":"struct MEP2542.ProofArray[]","name":"proofs","type":"tuple[]"},{"internalType":"uint256[]","name":"epochIds","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"internalType":"struct MEP2542.RewardInfo[]","name":"rewards","type":"tuple[]"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"epochIds","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"internalType":"struct MEP2542.RewardInfo[]","name":"rewards","type":"tuple[]"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"claimRewardsVerified","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimVerifier","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"controllers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochExpiredTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"epochReleaseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"internalType":"uint256[]","name":"epochNumbers","type":"uint256[]"}],"name":"getMinerClaimedEpochs","outputs":[{"internalType":"bool[]","name":"","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochNumber","type":"uint256"},{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"}],"name":"getMinerOnlineStatus","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"internalType":"uint256[]","name":"epochIds","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"internalType":"struct MEP2542.RewardInfo[]","name":"rewards","type":"tuple[]"}],"name":"getRewardHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardTokenInfo","outputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"internalType":"struct MEP2542.RewardTokenInfo[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getUserSelectedToken","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"address","name":"_ERC6551Registry","type":"address"},{"internalType":"address","name":"_ERC6551AccountImplAddr","type":"address"},{"internalType":"address","name":"_MEP1004Addr","type":"address"},{"internalType":"address","name":"_sensorToken","type":"address"},{"internalType":"uint256","name":"_epochExpiredTime","type":"uint256"},{"internalType":"uint256","name":"_maxSelectToken","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxSelectToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochNumber","type":"uint256"},{"internalType":"bytes32","name":"rewardMerkleRoot","type":"bytes32"},{"internalType":"bytes","name":"statusBitMap","type":"bytes"}],"name":"releaseEpoch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"removeRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardMerkleRoots","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardTokens","outputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"selectToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sensorToken","outputs":[{"internalType":"contract SensorToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_verifier","type":"address"}],"name":"setClaimVerifier","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_epochExpiredTime","type":"uint256"}],"name":"setEpochExpiredTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxSelectToken","type":"uint256"}],"name":"setMaxSelectToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"},{"internalType":"uint256","name":"amountPerEpoch","type":"uint256"}],"name":"setRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"MEP1004TokenId","type":"uint256"},{"components":[{"internalType":"bytes32[]","name":"proofs","type":"bytes32[]"}],"internalType":"struct MEP2542.ProofArray[]","name":"proofs","type":"tuple[]"},{"internalType":"uint256[]","name":"epochIds","type":"uint256[]"},{"components":[{"internalType":"address[]","name":"token","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"internalType":"struct MEP2542.RewardInfo[]","name":"rewards","type":"tuple[]"}],"name":"verifyMerkleProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]', 'MEP2542', ); @@ -26,8 +26,23 @@ class MEP2542 extends _i1.GeneratedContract { /// The optional [atBlock] parameter can be used to view historical data. When /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. - Future<_i2.Uint8List> DOMAIN_SEPARATOR({_i1.BlockNum? atBlock}) async { + Future<_i2.Uint8List> CLAIM_PERMIT_TYPEHASH({_i1.BlockNum? atBlock}) async { final function = self.abi.functions[0]; + assert(checkSignature(function, 'ef612d06')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i2.Uint8List); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> DOMAIN_SEPARATOR({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; assert(checkSignature(function, '3644e515')); final params = []; final response = await read( @@ -43,7 +58,7 @@ class MEP2542 extends _i1.GeneratedContract { /// latest on-chain block will be used. Future<_i1.EthereumAddress> ERC6551AccountImplAddr( {_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[1]; + final function = self.abi.functions[2]; assert(checkSignature(function, '4b90136c')); final params = []; final response = await read( @@ -58,7 +73,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i1.EthereumAddress> ERC6551Registry({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[2]; + final function = self.abi.functions[3]; assert(checkSignature(function, 'adbcef11')); final params = []; final response = await read( @@ -73,7 +88,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i1.EthereumAddress> MEP1004Token_({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[3]; + final function = self.abi.functions[4]; assert(checkSignature(function, '048dc9e7')); final params = []; final response = await read( @@ -88,7 +103,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i2.Uint8List> PERMIT_TYPEHASH({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[4]; + final function = self.abi.functions[5]; assert(checkSignature(function, '30adf81f')); final params = []; final response = await read( @@ -106,7 +121,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[5]; + final function = self.abi.functions[6]; assert(checkSignature(function, '5d79343d')); final params = []; return write( @@ -127,7 +142,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[6]; + final function = self.abi.functions[7]; assert(checkSignature(function, '0e56dddb')); final params = [ token, @@ -154,7 +169,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[7]; + final function = self.abi.functions[8]; assert(checkSignature(function, '89c64b7d')); final params = [ MEP1004TokenId, @@ -171,16 +186,60 @@ class MEP2542 extends _i1.GeneratedContract { ); } + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future claimRewardsVerified( + BigInt MEP1004TokenId, + _i1.EthereumAddress to, + List epochIds, + List rewards, + _i2.Uint8List signature, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, 'b31046cd')); + final params = [ + MEP1004TokenId, + to, + epochIds, + rewards, + signature, + ]; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> claimVerifier({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, 'a93539d0')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i1.EthereumAddress); + } + /// The optional [atBlock] parameter can be used to view historical data. When /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future controllers( - _i1.EthereumAddress $param8, { + _i1.EthereumAddress $param13, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[8]; + final function = self.abi.functions[11]; assert(checkSignature(function, 'da8c229e')); - final params = [$param8]; + final params = [$param13]; final response = await read( function, params, @@ -193,7 +252,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future currentEpoch({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[9]; + final function = self.abi.functions[12]; assert(checkSignature(function, '76671808')); final params = []; final response = await read( @@ -208,7 +267,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future epochExpiredTime({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[10]; + final function = self.abi.functions[13]; assert(checkSignature(function, 'f0645620')); final params = []; final response = await read( @@ -223,12 +282,12 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future epochReleaseTime( - BigInt $param9, { + BigInt $param14, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[11]; + final function = self.abi.functions[14]; assert(checkSignature(function, '977391a9')); - final params = [$param9]; + final params = [$param14]; final response = await read( function, params, @@ -245,7 +304,7 @@ class MEP2542 extends _i1.GeneratedContract { List epochNumbers, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[12]; + final function = self.abi.functions[15]; assert(checkSignature(function, 'aa4553b9')); final params = [ MEP1004TokenId, @@ -267,7 +326,7 @@ class MEP2542 extends _i1.GeneratedContract { BigInt MEP1004TokenId, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[13]; + final function = self.abi.functions[16]; assert(checkSignature(function, 'f7bdde4d')); final params = [ epochNumber, @@ -281,11 +340,35 @@ class MEP2542 extends _i1.GeneratedContract { return (response[0] as bool); } + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> getRewardHash( + BigInt MEP1004TokenId, + List epochIds, + List rewards, { + _i1.BlockNum? atBlock, + }) async { + final function = self.abi.functions[17]; + assert(checkSignature(function, 'a61c742b')); + final params = [ + MEP1004TokenId, + epochIds, + rewards, + ]; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i2.Uint8List); + } + /// The optional [atBlock] parameter can be used to view historical data. When /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future> getRewardTokenInfo({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[14]; + final function = self.abi.functions[18]; assert(checkSignature(function, '647428b9')); final params = []; final response = await read( @@ -303,7 +386,7 @@ class MEP2542 extends _i1.GeneratedContract { _i1.EthereumAddress account, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[15]; + final function = self.abi.functions[19]; assert(checkSignature(function, '54a61599')); final params = [account]; final response = await read( @@ -328,7 +411,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[16]; + final function = self.abi.functions[20]; assert(checkSignature(function, 'b33f9527')); final params = [ _treasury, @@ -351,7 +434,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future maxSelectToken({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[17]; + final function = self.abi.functions[21]; assert(checkSignature(function, 'b9dbcb02')); final params = []; final response = await read( @@ -366,7 +449,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i1.EthereumAddress> owner({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[18]; + final function = self.abi.functions[22]; assert(checkSignature(function, '8da5cb5b')); final params = []; final response = await read( @@ -387,7 +470,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[19]; + final function = self.abi.functions[23]; assert(checkSignature(function, 'b780a70b')); final params = [ epochNumber, @@ -410,7 +493,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[20]; + final function = self.abi.functions[24]; assert(checkSignature(function, '3d509c97')); final params = [token]; return write( @@ -428,7 +511,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[21]; + final function = self.abi.functions[25]; assert(checkSignature(function, '715018a6')); final params = []; return write( @@ -443,12 +526,12 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i2.Uint8List> rewardMerkleRoots( - BigInt $param26, { + BigInt $param34, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[22]; + final function = self.abi.functions[26]; assert(checkSignature(function, '43fef2f8')); - final params = [$param26]; + final params = [$param34]; final response = await read( function, params, @@ -461,12 +544,12 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future rewardTokens( - BigInt $param27, { + BigInt $param35, { _i1.BlockNum? atBlock, }) async { - final function = self.abi.functions[23]; + final function = self.abi.functions[27]; assert(checkSignature(function, '7bb7bed1')); - final params = [$param27]; + final params = [$param35]; final response = await read( function, params, @@ -484,7 +567,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[24]; + final function = self.abi.functions[28]; assert(checkSignature(function, '2fbde9ba')); final params = [ tokens, @@ -502,7 +585,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i1.EthereumAddress> sensorToken({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[25]; + final function = self.abi.functions[29]; assert(checkSignature(function, '680d65fa')); final params = []; final response = await read( @@ -513,6 +596,25 @@ class MEP2542 extends _i1.GeneratedContract { return (response[0] as _i1.EthereumAddress); } + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setClaimVerifier( + _i1.EthereumAddress _verifier, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[30]; + assert(checkSignature(function, '38eb8425')); + final params = [_verifier]; + return write( + credentials, + transaction, + function, + params, + ); + } + /// The optional [transaction] parameter can be used to override parameters /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. @@ -522,7 +624,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[26]; + final function = self.abi.functions[31]; assert(checkSignature(function, 'e0dba60f')); final params = [ controller, @@ -536,6 +638,25 @@ class MEP2542 extends _i1.GeneratedContract { ); } + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setEpochExpiredTime( + BigInt _epochExpiredTime, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[32]; + assert(checkSignature(function, '6d31a27f')); + final params = [_epochExpiredTime]; + return write( + credentials, + transaction, + function, + params, + ); + } + /// The optional [transaction] parameter can be used to override parameters /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. @@ -544,7 +665,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[27]; + final function = self.abi.functions[33]; assert(checkSignature(function, '6d4b9712')); final params = [_maxSelectToken]; return write( @@ -565,7 +686,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[28]; + final function = self.abi.functions[34]; assert(checkSignature(function, '2e35e36f')); final params = [ token, @@ -588,7 +709,7 @@ class MEP2542 extends _i1.GeneratedContract { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { - final function = self.abi.functions[29]; + final function = self.abi.functions[35]; assert(checkSignature(function, 'f2fde38b')); final params = [newOwner]; return write( @@ -603,7 +724,7 @@ class MEP2542 extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i1.EthereumAddress> treasury({_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[30]; + final function = self.abi.functions[36]; assert(checkSignature(function, '61d027b3')); final params = []; final response = await read( @@ -614,6 +735,56 @@ class MEP2542 extends _i1.GeneratedContract { return (response[0] as _i1.EthereumAddress); } + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future verifyMerkleProof( + BigInt MEP1004TokenId, + List proofs, + List epochIds, + List rewards, { + _i1.BlockNum? atBlock, + }) async { + final function = self.abi.functions[37]; + assert(checkSignature(function, '6a3780c4')); + final params = [ + MEP1004TokenId, + proofs, + epochIds, + rewards, + ]; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as bool); + } + + /// Returns a live stream of all BulkClaimedReward events emitted by this contract. + Stream bulkClaimedRewardEvents({ + _i1.BlockNum? fromBlock, + _i1.BlockNum? toBlock, + }) { + final event = self.event('BulkClaimedReward'); + final filter = _i1.FilterOptions.events( + contract: self, + event: event, + fromBlock: fromBlock, + toBlock: toBlock, + ); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults( + result.topics!, + result.data!, + ); + return BulkClaimedReward( + decoded, + result, + ); + }); + } + /// Returns a live stream of all ClaimedReward events emitted by this contract. Stream claimedRewardEvents({ _i1.BlockNum? fromBlock, @@ -748,6 +919,23 @@ class RewardTokens { final BigInt amountPerEpoch; } +class BulkClaimedReward { + BulkClaimedReward( + List response, + this.event, + ) : miner = (response[0] as _i1.EthereumAddress), + epochIds = (response[1] as List).cast(), + rewardInfos = (response[2] as List).cast(); + + final _i1.EthereumAddress miner; + + final List epochIds; + + final List rewardInfos; + + final _i1.FilterEvent event; +} + class ClaimedReward { ClaimedReward( List response, From 13a6111d5f3fd5c3a148e2af1fe6ff9a8eba6ce0 Mon Sep 17 00:00:00 2001 From: reasje Date: Tue, 27 Feb 2024 15:11:43 +0330 Subject: [PATCH 3/3] feat: Webview js channel & miner dapp interaction --- .../open_dapp/open_dapp_presenter.dart | 280 +++++++++++------- .../open_dapp/open_dapp_state.dart | 4 +- packages/shared | 2 +- 3 files changed, 179 insertions(+), 107 deletions(-) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 97a67c8f..1015ebe0 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -7,6 +7,7 @@ import 'package:datadashwallet/features/dapps/subfeatures/open_dapp/domain/dapps import 'package:datadashwallet/features/dapps/subfeatures/open_dapp/widgets/add_asset_dialog.dart'; import 'package:datadashwallet/features/dapps/subfeatures/open_dapp/widgets/swtich_network_dialog.dart'; import 'package:datadashwallet/features/dapps/subfeatures/open_dapp/widgets/typed_message_dialog.dart'; +import 'package:datadashwallet/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:mxc_logic/mxc_logic.dart'; @@ -35,6 +36,7 @@ class OpenDAppPresenter extends CompletePresenter { late final _customTokensUseCase = ref.read(customTokensUseCaseProvider); late final _errorUseCase = ref.read(errorUseCaseProvider); late final _launcherUseCase = ref.read(launcherUseCaseProvider); + late final _dAppHooksUseCase = ref.read(dAppHooksUseCaseProvider); @override void initState() { @@ -52,6 +54,10 @@ class OpenDAppPresenter extends CompletePresenter { notify(() => state.network = value); } }); + + listen(_dAppHooksUseCase.dappHooksData, (value) { + notify(() => state.dappHooksData = value); + }); } void onWebViewCreated(InAppWebViewController controller) async { @@ -152,9 +158,6 @@ class OpenDAppPresenter extends CompletePresenter { } void recordTransaction(TransactionModel tx) { - // final timeStamp = DateTime.now(); - // const txStatus = TransactionStatus.pending; - // const txType = TransactionType.contractCall; final currentNetwork = state.network!; final chainId = currentNetwork.chainId; final token = Token( @@ -166,15 +169,6 @@ class OpenDAppPresenter extends CompletePresenter { ); tx = tx.copyWith(token: token); - // final tx = TransactionModel( - // hash: hash, - // timeStamp: timeStamp, - // status: txStatus, - // type: txType, - // value: null, - // token: token, - // action: null, - // ); _transactionHistoryUseCase.spyOnTransaction( tx, @@ -434,20 +428,13 @@ class OpenDAppPresenter extends CompletePresenter { } void setChain(int? id) { - state.webviewController?.setChain(getConfig(), state.network!.chainId, id); + state.webviewController + ?.setChain(getProviderConfig(), state.network!.chainId, id); } - String getConfig() { - return """{ - ethereum: { - chainId: ${state.network!.chainId}, - rpcUrl: "${state.network!.web3RpcHttpUrl}", - address: "${state.account!.address}", - isDebug: true, - networkVersion: "${state.network!.chainId}", - isMetaMask: true - } - }"""; + String getProviderConfig() { + return JSChannelScripts.walletProviderInfoScript(state.network!.chainId, + state.network!.web3RpcHttpUrl, state.account!.address); } void copy(List params) { @@ -459,11 +446,10 @@ class OpenDAppPresenter extends CompletePresenter { } void injectCopyHandling() { - state.webviewController!.evaluateJavascript( - source: - 'javascript:navigator.clipboard.writeText = (msg) => { return window.flutter_inappwebview?.callHandler("axs-wallet-copy-clipboard", msg); }'); + state.webviewController! + .evaluateJavascript(source: JSChannelScripts.clipboardHandlerScript); state.webviewController!.addJavaScriptHandler( - handlerName: 'axs-wallet-copy-clipboard', + handlerName: JSChannelEvents.axsWalletCopyClipboard, callback: (args) { copy(args); }, @@ -537,85 +523,11 @@ class OpenDAppPresenter extends CompletePresenter { final settleDuration = const Duration(milliseconds: 400); injectScrollDetector() { - String jsCode = """ - var pStart = { x: 0, y: 0 }; - var pStop = { x: 0, y: 0 }; - - function swipeStart(e) { - if (typeof e["targetTouches"] !== "undefined") { - var touch = e.targetTouches[0]; - pStart.x = touch.screenX; - pStart.y = touch.screenY; - } else { - pStart.x = e.screenX; - pStart.y = e.screenY; - } - } - - function swipeEnd(e) { - if (typeof e["changedTouches"] !== "undefined") { - var touch = e.changedTouches[0]; - pStop.x = touch.screenX; - pStop.y = touch.screenY; - } else { - pStop.x = e.screenX; - pStop.y = e.screenY; - } - - swipeCheck(); - } - - function swipeCheck() { - var changeY = pStart.y - pStop.y; - var changeX = pStart.x - pStop.x; - if (isPullDown(changeY, changeX)) { - window.flutter_inappwebview?.callHandler("axs-scroll-detector", true); - } else if (isPullUp(changeY, changeX)) { - window.flutter_inappwebview?.callHandler("axs-scroll-detector", false); - } - } - - function isPullDown(dY, dX) { - // methods of checking slope, length, direction of line created by swipe action - console.log(dY); - console.log(dX ); - return ( - dY < 0 && - ((Math.abs(dX) <= 100 && Math.abs(dY) >= 100 ) || - (Math.abs(dX) / Math.abs(dY) <= 0.1 && dY >= 60)) - ); - } - - function isPullUp(dY, dX) { - // Check if the gesture is a pull-up - console.log(dY); - console.log(dX); - return ( - dY > 0 && - ((Math.abs(dX) <= 100 && Math.abs(dY) >= 100) || - (Math.abs(dX) / Math.abs(dY) <= 0.1 && dY >= 60)) - ); - } - - document.addEventListener( - "touchstart", - function (e) { - swipeStart(e); - }, - false - ); - document.addEventListener( - "touchend", - function (e) { - swipeEnd(e); - }, - false - ); - """; - state.webviewController!.evaluateJavascript(source: jsCode); + state.webviewController! + .evaluateJavascript(source: JSChannelScripts.overScrollScript); state.webviewController!.addJavaScriptHandler( - handlerName: 'axs-scroll-detector', + handlerName: JSChannelEvents.axsWalletScrollDetector, callback: (args) { if (args[0] is bool) { args[0] == true ? showPanel() : hidePanel(); @@ -681,4 +593,162 @@ class OpenDAppPresenter extends CompletePresenter { resetDoubleTapTime(); } } + + // call this on webview created + void injectMinerDappListeners() { + // Making It easy for accessing axs wallet + // use this way window.axs.callHandler + state.webviewController!.evaluateJavascript( + source: JSChannelScripts.axsWalletObjectInjectScript( + JSChannelConfig.axsWalletJSObjectName)); + + state.webviewController!.evaluateJavascript( + source: JSChannelScripts.axsWalletJSHandler( + JSChannelConfig.axsWalletJSObjectName, + JSChannelEvents.axsReadyEvent, {})); + + state.webviewController!.addJavaScriptHandler( + handlerName: JSChannelEvents.changeCronTransitionEvent, + callback: (args) => + jsChannelErrorHandler(args, handleChangeCronTransition)); + state.webviewController!.addJavaScriptHandler( + handlerName: JSChannelEvents.changeCronTransitionStatusEvent, + callback: (args) => + jsChannelErrorHandler(args, handleChangeCronTransitionStatusEvent)); + state.webviewController!.addJavaScriptHandler( + handlerName: JSChannelEvents.getSystemInfoEvent, + callback: (args) => jsChannelErrorHandler(args, handleGetSystemInfo)); + state.webviewController!.addJavaScriptHandler( + handlerName: JSChannelEvents.goToAdvancedSettingsEvent, + callback: (args) => + jsChannelErrorHandler(args, handleGoToAdvancedSettings)); + } + + AXSJSChannelResponseModel jsChannelErrorHandler(List args, + Function(Map, AXSCronServices) callback) { + try { + final channelData = args[0]; + final channelDataMap = json.decode(channelData) as Map; + final axsCronService = + AXSCronServicesExtension.getCronServiceFromJson(channelDataMap); + return callback(channelDataMap, axsCronService); + } catch (e) { + final response = AXSJSChannelResponseModel( + status: AXSJSChannelResponseStatus.failed, + data: null, + message: e.toString()); + return response; + } + } + + // Update via functions & get data via steam & send the data via event eaach time + // ready => updateSystemInfo (service statues, mining service status, time, selected miners, camera permission location permission) + + AXSJSChannelResponseModel handleChangeCronTransition( + Map channelData, AXSCronServices axsCronService) { + final axsCronService = + AXSCronServicesExtension.getCronServiceFromJson(channelData); + if (axsCronService == AXSCronServices.miningAutoClaimCron) { + ChangeCronTransitionRequestModel; + final changeCronTransitionRequestModel = + ChangeCronTransitionRequestModel.fromMap( + channelData, MiningCronServiceDataModel.fromMap); + + // Here i change the data thaqt won't effect the + final currentDappHooksData = state.dappHooksData; + final minersList = changeCronTransitionRequestModel.data?.minersList ?? + currentDappHooksData.minerHooks.selectedMiners; + final time = changeCronTransitionRequestModel.data?.time ?? + currentDappHooksData.minerHooks.time; + final updatedDappHooksData = currentDappHooksData.copyWith( + minerHooks: currentDappHooksData.minerHooks + .copyWith(selectedMiners: minersList, time: time)); + _dAppHooksUseCase.updateItem(updatedDappHooksData); + + final responseData = CronServiceDataModel.fromDAppHooksData( + axsCronService, + updatedDappHooksData, + MiningCronServiceDataModel.fromDAppHooksData(updatedDappHooksData)); + + final response = AXSJSChannelResponseModel( + status: AXSJSChannelResponseStatus.success, + data: responseData, + message: null); + return response; + } else { + throw 'Unknown service'; + } + } + + AXSJSChannelResponseModel handleChangeCronTransitionStatusEvent( + Map channelData, AXSCronServices axsCronService) { + if (axsCronService == AXSCronServices.miningAutoClaimCron) { + final status = channelData['status']; + final dappHooksData = state.dappHooksData; + final delay = dappHooksData.duration; + + DAppHooksModel updatedDappHooksData; + if (status) { + updatedDappHooksData = dappHooksData.copyWith(enabled: status); + _dAppHooksUseCase.startDAppHooksService(delay); + } + + updatedDappHooksData = dappHooksData.copyWith( + minerHooks: dappHooksData.minerHooks.copyWith(enabled: status)); + _dAppHooksUseCase.updateItem(updatedDappHooksData); + + final responseData = CronServiceDataModel.fromDAppHooksData( + axsCronService, + updatedDappHooksData, + MiningCronServiceDataModel.fromDAppHooksData(updatedDappHooksData)); + final response = AXSJSChannelResponseModel( + status: AXSJSChannelResponseStatus.success, + message: null, + data: responseData); + return response; + } else { + throw 'Unknown cron service'; + } + } + + void addMiningAutoClaim() { + // if cron_claim + } + void removeMiningAutoClaim() { + // if cron_claim + } + + void handleGoToAdvancedSettingsEvent() {} + AXSJSChannelResponseModel handleGetSystemInfo( + Map channelData, AXSCronServices axsCronService) { + if (axsCronService == AXSCronServices.miningAutoClaimCron) { + final dappHooksData = state.dappHooksData; + + final responseData = CronServiceDataModel.fromDAppHooksData( + axsCronService, + dappHooksData, + MiningCronServiceDataModel.fromDAppHooksData(dappHooksData)); + final response = AXSJSChannelResponseModel( + status: AXSJSChannelResponseStatus.success, + message: null, + data: responseData); + return response; + } else { + throw 'Unknown cron service'; + } + } + + AXSJSChannelResponseModel handleGoToAdvancedSettings( + Map channelData, AXSCronServices axsCronService) { + goToAdvancedSettings(); + final response = AXSJSChannelResponseModel( + status: AXSJSChannelResponseStatus.success, message: null, data: null); + return response; + } + + void goToAdvancedSettings() { + navigator!.push(route( + const DAppHooksPage(), + )); + } } diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_state.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_state.dart index 6f649098..11646958 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_state.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_state.dart @@ -12,6 +12,7 @@ class OpenDAppState with EquatableMixin { int panelHideTimer = 5; Uri? currentUrl; bool isSecure = false; + late DAppHooksModel dappHooksData; @override List get props => [ @@ -21,6 +22,7 @@ class OpenDAppState with EquatableMixin { network, animationController, currentUrl, - isSecure + isSecure, + dappHooksData ]; } diff --git a/packages/shared b/packages/shared index 092c231e..2a7f2d4c 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 092c231e5919c26162acd60a686f078511c960e8 +Subproject commit 2a7f2d4c744e4e2b84afd52a6deb73b105b16bd6