| 1 | import 'dart:io'; |
| 2 | |
| 3 | import 'package:cake_wallet/entities/exchange_api_mode.dart'; |
| 4 | import 'package:cake_wallet/entities/fiat_api_mode.dart'; |
| 5 | import 'package:cake_wallet/entities/new_ui_entities/list_item/list_item_regular_row.dart'; |
| 6 | import 'package:cake_wallet/entities/new_ui_entities/list_item/list_item_selector.dart'; |
| 7 | import 'package:cake_wallet/entities/new_ui_entities/list_item/list_item_toggle.dart'; |
| 8 | import 'package:cake_wallet/generated/i18n.dart'; |
| 9 | import 'package:cake_wallet/new-ui/widgets/modal_header.dart'; |
| 10 | import 'package:cake_wallet/new-ui/widgets/modal_page_wrapper.dart'; |
| 11 | import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart'; |
| 12 | import 'package:cake_wallet/routes.dart'; |
| 13 | import 'package:cake_wallet/src/screens/base_page.dart'; |
| 14 | import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; |
| 15 | import 'package:cake_wallet/src/widgets/new_list_row/new_list_section.dart'; |
| 16 | import 'package:cake_wallet/src/widgets/picker.dart'; |
| 17 | import 'package:cake_wallet/utils/feature_flag.dart'; |
| 18 | import 'package:cake_wallet/utils/show_pop_up.dart'; |
| 19 | import 'package:cake_wallet/view_model/settings/connection_sync_view_model.dart'; |
| 20 | import 'package:flutter/material.dart'; |
| 21 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 22 | |
| 23 | class ConnectionSyncPage extends BasePage { |
| 24 | ConnectionSyncPage(this._connectionSyncViewModel); |
| 25 | |
| 26 | @override |
| 27 | bool get hideAppBar => true; |
| 28 | |
| 29 | final ConnectionSyncViewModel _connectionSyncViewModel; |
| 30 | |
| 31 | @override |
| 32 | Widget body(BuildContext context) { |
| 33 | return ModalPageWrapper( |
| 34 | topBar: ModalTopBar( |
| 35 | title: "", |
| 36 | leadingIcon: Icon(Icons.arrow_back_ios_new), |
| 37 | leadingSemanticLabel: S.of(context).seed_alert_back, |
| 38 | onLeadingPressed: () => Navigator.of(context).pop()), |
| 39 | header: ModalHeader( |
| 40 | iconPath: "assets/new-ui/settings_row_icons/connections.svg", |
| 41 | message: S.of(context).connections_desc, |
| 42 | title: S.of(context).connections), |
| 43 | content: Column( |
| 44 | mainAxisSize: MainAxisSize.min, |
| 45 | children: [ |
| 46 | Observer( |
| 47 | builder: (context) => NewListSections(sections: { |
| 48 | "": [ |
| 49 | if (FeatureFlag.isInAppTorEnabled) |
| 50 | ListItemToggle( |
| 51 | keyValue: "enable_builtin_tor", |
| 52 | label: S.of(context).enable_builtin_tor, |
| 53 | value: _connectionSyncViewModel.builtinTor, |
| 54 | onChanged: (val) { |
| 55 | _connectionSyncViewModel.setBuiltinTor(val, context); |
| 56 | }), |
| 57 | ListItemToggle( |
| 58 | keyValue: "disable_automatic_exchange_status_updates", |
| 59 | label: S.of(context).disable_automatic_exchange_status_updates, |
| 60 | value: _connectionSyncViewModel.disableAutomaticExchangeStatusUpdates, |
| 61 | onChanged: (val) { |
| 62 | _connectionSyncViewModel.setDisableAutomaticExchangeStatusUpdates(val); |
| 63 | }), |
| 64 | if (_connectionSyncViewModel.canUseBlinkProtection) |
| 65 | ListItemToggle( |
| 66 | keyValue: "can_use_blink_protection", |
| 67 | label: S.of(context).use_blink_protection, |
| 68 | value: _connectionSyncViewModel.useBlinkProtection, |
| 69 | onChanged: (val) { |
| 70 | _connectionSyncViewModel.setUseBlinkProtection(val); |
| 71 | }), |
| 72 | if (_connectionSyncViewModel.canUseEtherscan) |
| 73 | ListItemToggle( |
| 74 | keyValue: "can_use_etherscan", |
| 75 | label: S.of(context).etherscan_history, |
| 76 | value: _connectionSyncViewModel.useEtherscan, |
| 77 | onChanged: (val) { |
| 78 | _connectionSyncViewModel.setUseEtherscan(val); |
| 79 | }), |
| 80 | if (_connectionSyncViewModel.canUsePolygonScan) |
| 81 | ListItemToggle( |
| 82 | keyValue: "can_use_polygonscan", |
| 83 | label: S.of(context).polygonscan_history, |
| 84 | value: _connectionSyncViewModel.usePolygonScan, |
| 85 | onChanged: (val) { |
| 86 | _connectionSyncViewModel.setUsePolygonScan(val); |
| 87 | }), |
| 88 | if (_connectionSyncViewModel.canUseBaseScan) |
| 89 | ListItemToggle( |
| 90 | keyValue: "can_use_basescan", |
| 91 | label: S.of(context).basescan_history, |
| 92 | value: _connectionSyncViewModel.canUseBaseScan, |
| 93 | onChanged: (val) { |
| 94 | _connectionSyncViewModel.setUseBaseScan(val); |
| 95 | }), |
| 96 | if (_connectionSyncViewModel.canUseArbiScan) |
| 97 | ListItemToggle( |
| 98 | keyValue: "can_use_arbiscan", |
| 99 | label: S.of(context).arbiscan_history, |
| 100 | value: _connectionSyncViewModel.useArbiScan, |
| 101 | onChanged: (val) { |
| 102 | _connectionSyncViewModel.setUseArbiScan(val); |
| 103 | }), |
| 104 | if (_connectionSyncViewModel.canUseBscScan) |
| 105 | ListItemToggle( |
| 106 | keyValue: "can_use_bscscan", |
| 107 | label: S.of(context).bscscan_history, |
| 108 | value: _connectionSyncViewModel.useBscScan, |
| 109 | onChanged: (val) { |
| 110 | _connectionSyncViewModel.setUseBscScan(val); |
| 111 | }), |
| 112 | if (_connectionSyncViewModel.canUseTronGrid) |
| 113 | ListItemToggle( |
| 114 | keyValue: "can_use_trongrid", |
| 115 | label: S.of(context).trongrid_history, |
| 116 | value: _connectionSyncViewModel.useTronGrid, |
| 117 | onChanged: (val) { |
| 118 | _connectionSyncViewModel.setUseTronGrid(val); |
| 119 | }), |
| 120 | if (_connectionSyncViewModel.canUseMempoolFeeAPI) |
| 121 | ListItemToggle( |
| 122 | keyValue: "enable_mempool_api", |
| 123 | label: S.of(context).enable_mempool_api, |
| 124 | value: _connectionSyncViewModel.useMempoolFeeAPI, |
| 125 | onChanged: (bool isEnabled) async { |
| 126 | if (!isEnabled) { |
| 127 | final bool confirmation = await showPopUp<bool>( |
| 128 | context: context, |
| 129 | builder: (BuildContext context) { |
| 130 | return AlertWithTwoActions( |
| 131 | alertTitle: S.of(context).warning, |
| 132 | alertContent: S.of(context).disable_fee_api_warning, |
| 133 | rightButtonText: S.of(context).confirm, |
| 134 | leftButtonText: S.of(context).cancel, |
| 135 | actionRightButton: () => |
| 136 | Navigator.of(context).pop(true), |
| 137 | actionLeftButton: () => |
| 138 | Navigator.of(context).pop(false)); |
| 139 | }) ?? |
| 140 | false; |
| 141 | if (confirmation) { |
| 142 | _connectionSyncViewModel.setUseMempoolFeeAPI(isEnabled); |
| 143 | } |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | _connectionSyncViewModel.setUseMempoolFeeAPI(isEnabled); |
| 148 | }), |
| 149 | if (Platform.isAndroid && FeatureFlag.isBackgroundSyncEnabled) |
| 150 | ListItemRegularRow( |
| 151 | keyValue: "background_sync", |
| 152 | label: S.of(context).background_sync, |
| 153 | onTap: () => Navigator.of(context).pushNamed(Routes.backgroundSync)), |
| 154 | if (_connectionSyncViewModel.hasPowNodes) |
| 155 | ListItemRegularRow( |
| 156 | keyValue: "manage_pow_nodes", |
| 157 | label: S.of(context).manage_pow_nodes, |
| 158 | onTap: () => Navigator.of(context).pushNamed(Routes.managePowNodes), |
| 159 | ), |
| 160 | ListItemSelector( |
| 161 | keyValue: "fiat_api", |
| 162 | label: S.of(context).fiat_api, |
| 163 | options: [_connectionSyncViewModel.fiatApiMode.title], |
| 164 | onTap: () async { |
| 165 | final items = FiatApiMode.all; |
| 166 | |
| 167 | final selectedAtIndex = |
| 168 | items.indexOf(_connectionSyncViewModel.fiatApiMode); |
| 169 | |
| 170 | await showPopUp<void>( |
| 171 | context: context, |
| 172 | builder: (_) => Picker( |
| 173 | items: items, |
| 174 | selectedAtIndex: selectedAtIndex, |
| 175 | mainAxisAlignment: MainAxisAlignment.start, |
| 176 | onItemSelected: (FiatApiMode fiatApiMode) { |
| 177 | _connectionSyncViewModel.setFiatMode(fiatApiMode); |
| 178 | }, |
| 179 | isSeparated: false, |
| 180 | ), |
| 181 | ); |
| 182 | }), |
| 183 | ListItemSelector( |
| 184 | keyValue: "swap", |
| 185 | label: S.of(context).swap, |
| 186 | options: [_connectionSyncViewModel.exchangeStatus.title], |
| 187 | onTap: () async { |
| 188 | final items = ExchangeApiMode.all; |
| 189 | |
| 190 | final selectedAtIndex = |
| 191 | items.indexOf(_connectionSyncViewModel.exchangeStatus); |
| 192 | |
| 193 | await showPopUp<void>( |
| 194 | context: context, |
| 195 | builder: (_) => Picker( |
| 196 | items: items, |
| 197 | selectedAtIndex: selectedAtIndex, |
| 198 | mainAxisAlignment: MainAxisAlignment.start, |
| 199 | onItemSelected: (ExchangeApiMode mode) { |
| 200 | _connectionSyncViewModel.setExchangeApiMode(mode); |
| 201 | }, |
| 202 | isSeparated: false, |
| 203 | ), |
| 204 | ); |
| 205 | }), |
| 206 | ListItemRegularRow( |
| 207 | keyValue: "domain_lookups", |
| 208 | label: S.of(context).domain_looks_up, |
| 209 | onTap: () => Navigator.of(context).pushNamed(Routes.domainLookupsPage)), |
| 210 | if (_connectionSyncViewModel.hasRescan) |
| 211 | ListItemRegularRow( |
| 212 | keyValue: "rescan", |
| 213 | label: S.of(context).rescan, |
| 214 | onTap: () => Navigator.of(context).pushNamed(Routes.rescan)) |
| 215 | ], |
| 216 | })), |
| 217 | ], |
| 218 | ), |
| 219 | ); |
| 220 | } |
| 221 | } |