Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@
"statistics": "Statistics",
"ibcTransferFieldTitle": "IBC Transfer",
"ibcTransferFieldSubtitle": "Send to another Cosmos chain",
"ibcChannel": "IBC Channel",
"ibcChannelHint": "channel-141",
"ibcChannelRequired": "IBC channel is required",
"ibcChannelInvalidFormat": "Invalid format. Use: channel-<number>",
"successPageHeadline": "Withdrawal Successful",
"successPageBodySmall": "Transaction Hash:",
"withdrawErrorCardTileTitle": "Technical Details",
Expand Down
26 changes: 16 additions & 10 deletions lib/bloc/withdraw_form/withdraw_form_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,30 @@ class WithdrawFormBloc extends Bloc<WithdrawFormEvent, WithdrawFormState> {
WithdrawFormIbcChannelChanged event,
Emitter<WithdrawFormState> emit,
) {
if (event.channel.isEmpty) {
emit(
state.copyWith(
ibcChannel: () => event.channel,
ibcChannelError: () => TextError(error: 'Channel ID is required'),
),
);
return;
}
final ibcChannelError = _validateIbcChannel(event.channel);

emit(
state.copyWith(
ibcChannel: () => event.channel,
ibcChannelError: () => null,
ibcChannelError: () => ibcChannelError,
),
);
}

/// Validate format: channel-{number}
TextError? _validateIbcChannel(String channel) {
if (channel.isEmpty) {
return TextError(error: 'Channel ID is required');
}

final channelRegex = RegExp(r'^channel-\d+$');
if (!channelRegex.hasMatch(channel)) {
return TextError(error: 'Invalid format. Use: channel-<number>');
}

return null;
}

Future<void> _onPreviewSubmitted(
WithdrawFormPreviewSubmitted event,
Emitter<WithdrawFormState> emit,
Expand Down
5 changes: 3 additions & 2 deletions lib/bloc/withdraw_form/withdraw_form_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class WithdrawFormState extends Equatable {

bool get hasPreviewError => previewError != null;
bool get hasTransactionError => transactionError != null;
bool get hasAddressError =>
recipientAddressError != null;
bool get hasAddressError => recipientAddressError != null;
bool get hasValidationErrors =>
hasAddressError ||
amountError != null ||
Expand Down Expand Up @@ -186,6 +185,8 @@ class WithdrawFormState extends Equatable {
: null,
memo: memo,
ibcTransfer: isIbcTransfer ? true : null,
ibcSourceChannel:
ibcChannel?.isNotEmpty == true ? ibcChannel!.trim() : null,
isMax: isMaxAmount,
);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/codegen_loader.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ abstract class LocaleKeys {
static const statistics = 'statistics';
static const ibcTransferFieldTitle = 'ibcTransferFieldTitle';
static const ibcTransferFieldSubtitle = 'ibcTransferFieldSubtitle';
static const ibcChannel = 'ibcChannel';
static const ibcChannelHint = 'ibcChannelHint';
static const ibcChannelRequired = 'ibcChannelRequired';
static const ibcChannelInvalidFormat = 'ibcChannelInvalidFormat';
static const successPageHeadline = 'successPageHeadline';
static const successPageBodySmall = 'successPageBodySmall';
static const withdrawErrorCardTileTitle = 'withdrawErrorCardTileTitle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class FeeSection extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(LocaleKeys.networkFee.tr(), style: Theme.of(context).textTheme.titleMedium),
Text(LocaleKeys.networkFee.tr(),
style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 8),
const CustomFeeToggle(),
if (state.isCustomFee) ...[
Expand Down Expand Up @@ -578,26 +579,66 @@ class IbcTransferField extends StatelessWidget {
}
}

class IbcChannelField extends StatelessWidget {
class IbcChannelField extends StatefulWidget {
const IbcChannelField({super.key});

@override
State<IbcChannelField> createState() => _IbcChannelFieldState();
}

class _IbcChannelFieldState extends State<IbcChannelField> {
late final TextEditingController _controller;

@override
void initState() {
super.initState();
_controller = TextEditingController();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return BlocBuilder<WithdrawFormBloc, WithdrawFormState>(
return BlocConsumer<WithdrawFormBloc, WithdrawFormState>(
listenWhen: (previous, current) =>
previous.ibcChannel != current.ibcChannel &&
current.ibcChannel != _controller.text,
listener: (context, state) {
// Only update controller if the bloc state differs from current text
// This prevents the cursor from jumping when user is typing
if (state.ibcChannel != _controller.text) {
_controller.text = state.ibcChannel ?? '';
}
},
buildWhen: (previous, current) =>
previous.ibcChannelError != current.ibcChannelError,
builder: (context, state) {
return UiTextFormField(
key: const Key('withdraw-ibc-channel-input'),
labelText: 'IBC Channel',
hintText: 'Enter IBC channel ID',
controller: _controller,
labelText: LocaleKeys.ibcChannel.tr(),
hintText: LocaleKeys.ibcChannelHint.tr(),
errorText: state.ibcChannelError?.message,
onChanged: (value) {
context
.read<WithdrawFormBloc>()
.add(WithdrawFormIbcChannelChanged(value ?? ''));
},
validator: (value) {
if (value?.isEmpty ?? true) {
return 'Please enter IBC channel';
return LocaleKeys.ibcChannelRequired.tr();
}

// Validate format: channel-<number>
final channelRegex = RegExp(r'^channel-\d+$');
if (!channelRegex.hasMatch(value!)) {
return LocaleKeys.ibcChannelInvalidFormat.tr();
}

return null;
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:web_dex/mm2/mm2_api/rpc/base.dart';
import 'package:web_dex/model/text_error.dart';
import 'package:web_dex/shared/utils/utils.dart';
import 'package:web_dex/views/wallet/coin_details/withdraw_form/widgets/fill_form/fields/fill_form_memo.dart';
import 'package:web_dex/views/wallet/coin_details/withdraw_form/widgets/fill_form/fields/fields.dart';
import 'package:web_dex/views/wallet/coin_details/withdraw_form/widgets/withdraw_form_header.dart';

class WithdrawForm extends StatefulWidget {
Expand Down Expand Up @@ -304,6 +305,14 @@ class WithdrawFormFillSection extends StatelessWidget {
: () => state.recipientAddressError?.message,
),
const SizedBox(height: 16),
if (state.asset.protocol is TendermintProtocol) ...[
const IbcTransferField(),
if (state.isIbcTransfer) ...[
const SizedBox(height: 16),
const IbcChannelField(),
],
const SizedBox(height: 16),
],
WithdrawAmountField(
asset: state.asset,
amount: state.amount,
Expand Down
6 changes: 3 additions & 3 deletions packages/komodo_ui_kit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ packages:
description:
path: "packages/komodo_defi_rpc_methods"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -104,7 +104,7 @@ packages:
description:
path: "packages/komodo_defi_types"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -113,7 +113,7 @@ packages:
description:
path: "packages/komodo_ui"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand Down
18 changes: 9 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ packages:
description:
path: "packages/komodo_cex_market_data"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.0.1"
Expand All @@ -657,7 +657,7 @@ packages:
description:
path: "packages/komodo_coins"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -666,7 +666,7 @@ packages:
description:
path: "packages/komodo_defi_framework"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0"
Expand All @@ -675,7 +675,7 @@ packages:
description:
path: "packages/komodo_defi_local_auth"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -684,7 +684,7 @@ packages:
description:
path: "packages/komodo_defi_rpc_methods"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -693,7 +693,7 @@ packages:
description:
path: "packages/komodo_defi_sdk"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -702,7 +702,7 @@ packages:
description:
path: "packages/komodo_defi_types"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -718,7 +718,7 @@ packages:
description:
path: "packages/komodo_ui"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -734,7 +734,7 @@ packages:
description:
path: "packages/komodo_wallet_build_transformer"
ref: dev
resolved-ref: "41b554d08ed3f42f9f784a488cedf9ab4b3b3313"
resolved-ref: "4ecbdaba11f572aa3c46603622ad42d7ee995b1a"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand Down
Loading