Skip to content

Commit

Permalink
chore: clean up the CoinReceiveRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-brontes committed Jan 7, 2025
1 parent 00b0af3 commit d27ac79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:ion/app/extensions/num.dart';
import 'package:ion/app/extensions/theme_data.dart';
import 'package:ion/app/features/wallet/model/coin_data.c.dart';
import 'package:ion/app/features/wallet/model/network_type.dart';
import 'package:ion/app/features/wallet/views/pages/coins_flow/coin_receive_modal/model/coin_receive_modal_data.c.dart';
import 'package:ion/app/features/wallet/views/pages/coins_flow/providers/send_asset_form_provider.c.dart';
import 'package:ion/app/features/wallet/views/pages/coins_flow/receive_coins/providers/receive_coins_form_provider.c.dart';
import 'package:ion/app/features/wallet/views/pages/wallet_page/components/balance/balance_actions.dart';
Expand Down Expand Up @@ -67,14 +66,11 @@ class Balance extends ConsumerWidget {
padding: EdgeInsets.only(bottom: 20.0.s, top: 11.0.s),
child: BalanceActions(
onReceive: () {
ref.read(receiveCoinsFormControllerProvider.notifier).setNetwork(networkType);
ref.read(receiveCoinsFormControllerProvider.notifier)
..setCoin(coinData)
..setNetwork(networkType);

CoinReceiveRoute(
$extra: CoinReceiveModalData(
coinData: coinData,
networkType: networkType,
),
).push<void>(context);
CoinReceiveRoute().push<void>(context);
},
onSend: () {
ref.read(sendAssetFormControllerProvider().notifier).setCoin(coinData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: ice License 1.0

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/components/list_item/list_item.dart';
import 'package:ion/app/components/screen_offset/screen_bottom_offset.dart';
Expand All @@ -12,7 +11,6 @@ import 'package:ion/app/extensions/num.dart';
import 'package:ion/app/extensions/theme_data.dart';
import 'package:ion/app/features/wallet/model/network_type.dart';
import 'package:ion/app/features/wallet/views/pages/coins_flow/coin_receive_modal/components/coin_address_tile/coin_address_tile.dart';
import 'package:ion/app/features/wallet/views/pages/coins_flow/coin_receive_modal/model/coin_receive_modal_data.c.dart';
import 'package:ion/app/features/wallet/views/pages/coins_flow/receive_coins/providers/receive_coins_form_provider.c.dart';
import 'package:ion/app/hooks/use_on_init.dart';
import 'package:ion/app/router/app_routes.c.dart';
Expand All @@ -21,22 +19,19 @@ import 'package:ion/app/router/components/navigation_app_bar/navigation_close_bu
import 'package:ion/app/router/components/sheet_content/sheet_content.dart';

class CoinReceiveModal extends HookConsumerWidget {
const CoinReceiveModal({required this.payload, super.key});

final CoinReceiveModalData payload;
const CoinReceiveModal({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final networkType = useState<NetworkType>(payload.networkType);
final receiveCoinState = ref.watch(receiveCoinsFormControllerProvider);

void updateNetwork(NetworkType network) {
networkType.value = network == NetworkType.all ? NetworkType.arbitrum : network;
ref.read(receiveCoinsFormControllerProvider.notifier).setNetwork(networkType.value);
final clarifiedNetwork = network == NetworkType.all ? NetworkType.arbitrum : network;
ref.read(receiveCoinsFormControllerProvider.notifier).setNetwork(clarifiedNetwork);
}

useOnInit(
() => updateNetwork(payload.networkType),
[payload],
() => updateNetwork(receiveCoinState.selectedNetwork),
);

return SheetContent(
Expand All @@ -53,7 +48,7 @@ class CoinReceiveModal extends HookConsumerWidget {
),
ScreenSideOffset.small(
child: CoinAddressTile(
coinData: payload.coinData,
coinData: receiveCoinState.selectedCoin,
),
),
SizedBox(
Expand All @@ -62,9 +57,9 @@ class CoinReceiveModal extends HookConsumerWidget {
ScreenSideOffset.small(
child: ListItem(
title: Text(context.i18n.wallet_network),
subtitle: Text(networkType.value.getDisplayName(context)),
subtitle: Text(receiveCoinState.selectedNetwork.getDisplayName(context)),
switchTitleStyles: true,
leading: networkType.value.iconAsset.icon(size: 36.0.s),
leading: receiveCoinState.selectedNetwork.iconAsset.icon(size: 36.0.s),
trailing: Text(
context.i18n.wallet_change,
style: context.theme.appTextThemes.caption.copyWith(
Expand Down
6 changes: 2 additions & 4 deletions lib/app/router/wallet_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,11 @@ class CoinsDetailsRoute extends BaseRouteData {
}

class CoinReceiveRoute extends BaseRouteData {
CoinReceiveRoute({required this.$extra})
CoinReceiveRoute()
: super(
child: CoinReceiveModal(payload: $extra),
child: const CoinReceiveModal(),
type: IceRouteType.bottomSheet,
);

final CoinReceiveModalData $extra;
}

class ManageCoinsRoute extends BaseRouteData {
Expand Down

0 comments on commit d27ac79

Please sign in to comment.