Skip to content

Commit

Permalink
feat: adjust stake unstake form
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Dec 12, 2024
1 parent cec3b5e commit 351137a
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 31 deletions.
6 changes: 5 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,9 @@
"welcomeBack": "Welcome back",
"deleteWalletSettings": "Settings: Delete wallet",
"disableStakeTitle": "You don't have enough balance to stake",
"disableStakeMessage": "The minimun amount to stake is 10,000 WIT"
"disableStakeMessage": "The minimun amount to stake is 10,000 WIT",
"stakeWithdrawalAddressText": "This is the address to create Stake transactions. Make sure this address is authorized to stake.",
"unstakeWithdrawalAddressText": "This is the address used to create Stake transactions.",
"validator": "Validator",
"validatorDescription": "Validator address that authorized staking."
}
5 changes: 4 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,8 @@
"deleteWalletSettings": "Configuración: Eliminar wallet",
"welcomeBack": "Bienvenido de nuevo",
"disableStakeTitle": "No tienes suficiente balance para hacer Stake",
"disableStakeMessage": "La cantidad minima para hacer Stake es de 10.000 WIT"
"disableStakeMessage": "La cantidad minima para hacer Stake es de 10.000 WIT",
"withdrawalAddressDescription": "Esta es tu direción para realizar transaction de Stake. Un nodo de Witnet debe autorizar esta address para realizar transactiones de Stake",
"validator": "Validador",
"validatorDescription": "Dirección del validador que autorizó el staking."
}
5 changes: 5 additions & 0 deletions lib/theme/dark_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
isDense: true,
isCollapsed: false,
contentPadding: EdgeInsets.all(16),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: WitnetPallet.darkGrey2, width: 1.0, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(BORDER_RADIUS),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: WitnetPallet.darkGrey2, width: 1.0, style: BorderStyle.solid),
Expand Down
5 changes: 5 additions & 0 deletions lib/theme/light_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
isDense: true,
isCollapsed: false,
contentPadding: const EdgeInsets.all(16),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: WitnetPallet.black, width: 1.0, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(BORDER_RADIUS),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: WitnetPallet.black, width: 1.0, style: BorderStyle.solid),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/stake_unstake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StakeUnstakeButtons extends StatelessWidget {
ApiDatabase db = Locator.instance.get<ApiDatabase>();
Wallet currentWallet = db.walletStorage.currentWallet;
late StakedBalanceInfo stakeInfo = currentWallet.stakedNanoWit();
bool allowStake = MIN_STAKING_AMOUNT_NANOWIT <
bool allowStake = MIN_STAKING_AMOUNT_NANOWIT <=
currentWallet.balanceNanoWit().availableNanoWit;

Future<void> _goToStakeScreen() async {
Expand Down
82 changes: 82 additions & 0 deletions lib/widgets/withdrawal_address.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:my_wit_wallet/widgets/copy_button.dart';
import 'package:my_wit_wallet/widgets/inputs/input_text.dart';

import 'package:my_wit_wallet/theme/extended_theme.dart';
import 'package:my_wit_wallet/util/get_localization.dart';
import 'package:my_wit_wallet/util/storage/scanned_content.dart';

class WithdrawerAddress extends InputText {
WithdrawerAddress({
required super.focusNode,
required super.styledTextController,
super.prefixIcon,
super.enabled = true,
super.errorText,
super.validator,
super.hint,
super.keyboardType,
super.obscureText = false,
this.route,
super.onChanged,
super.onEditingComplete,
super.onFieldSubmitted,
super.onTapOutside,
super.onTap,
super.onSuffixTap,
super.inputFormatters,
super.decoration,
super.maxLines = 1,
this.setAddressCallback,
});

final String? route;
final void Function(String, {bool? validate})? setAddressCallback;
@override
_WithdrawerAddressState createState() => _WithdrawerAddressState();
}

class _WithdrawerAddressState extends State<WithdrawerAddress> {
bool isScanQrFocused = false;
ScannedContent scannedContent = ScannedContent();
TextSelection? lastSelection;

@override
void initState() {
super.initState();
}

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

Widget build(BuildContext context) {
final theme = Theme.of(context);
final extendedTheme = theme.extension<ExtendedTheme>()!;

widget.styledTextController.setStyle(
extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
extendedTheme.monoLargeText!.copyWith(color: Colors.black),
);

return Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: [
widget.buildInput(
context: context,
decoration: widget.decoration ??
InputDecoration(
hintStyle: extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
hintText: localization.recipientAddress,
suffixIcon: Semantics(
label: localization.copyAddressLabel,
child: CopyButton(copyContent: 'copyContent')),
errorText: widget.errorText,
)),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import 'package:my_wit_wallet/widgets/inputs/input_authorization.dart';
import 'package:my_wit_wallet/widgets/inputs/input_slider.dart';
import 'package:my_wit_wallet/widgets/labeled_form_entry.dart';
import 'package:my_wit_wallet/widgets/layouts/send_transaction_layout.dart';
import 'package:my_wit_wallet/widgets/select.dart';
import 'package:my_wit_wallet/widgets/snack_bars.dart';
import 'package:my_wit_wallet/widgets/validations/address_input.dart';
import 'package:my_wit_wallet/widgets/validations/authorization_input.dart';
import 'package:my_wit_wallet/widgets/validations/validation_utils.dart';
import 'package:my_wit_wallet/widgets/validations/tx_amount_input.dart';
import 'package:my_wit_wallet/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/timelock_input.dart';
import 'package:my_wit_wallet/widgets/withdrawal_address.dart';
import 'package:my_wit_wallet/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/timelock_input.dart'
as timelockInput;
import 'package:my_wit_wallet/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/timelock_picker.dart';
import 'package:witnet/schema.dart';
import 'package:my_wit_wallet/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart';
Expand All @@ -35,7 +38,7 @@ import 'package:my_wit_wallet/util/storage/database/account.dart';
class RecipientStep extends StatefulWidget {
final Function nextAction;
final WalletStorage walletStorage;
final VoidCallback goNext;
final timelockInput.VoidCallback goNext;
final TransactionType transactionType;
final String routeName;

Expand Down Expand Up @@ -64,6 +67,7 @@ class RecipientStepState extends State<RecipientStep>
AddressInput _address = AddressInput.pure();
TxAmountInput _amount = TxAmountInput.pure();
AuthorizationInput _authorization = AuthorizationInput.pure();
String _selectedValidator = 'validator1';
final _amountController = StyledTextController();
final _amountFocusNode = FocusNode();
final _addressController = StyledTextController();
Expand Down Expand Up @@ -348,7 +352,7 @@ class RecipientStepState extends State<RecipientStep>
showAdvancedSettings
? Padding(
padding: EdgeInsets.only(left: 8, right: 8),
child: TimelockInput(
child: timelockInput.TimelockInput(
timelockSet: timelockSet,
onSelectedDate: _setTimeLock,
onClearTimelock: _clearTimeLock,
Expand Down Expand Up @@ -484,32 +488,57 @@ class RecipientStepState extends State<RecipientStep>
}

List<Widget> _buildWithdrawalAddressInput(ThemeData theme) {
_addressController.text = currentAccount.address;
return [
LabeledFormEntry(
label: localization.withdrawalAddress,
formEntry: InputAddress(
route: widget.routeName,
errorText: _address.error,
styledTextController: _addressController,
focusNode: _addressFocusNode,
keyboardType: TextInputType.text,
inputFormatters: [WitAddressFormatter()],
onChanged: (String value) {
setAddress(value);
},
onFieldSubmitted: (String value) {
showAuthorization
? _authorizationFocusNode.requestFocus()
: _amountFocusNode.requestFocus();
},
onTap: () {
_addressFocusNode.requestFocus();
},
onTapOutside: (event) {
_addressFocusNode.unfocus();
},
setAddressCallback: setAddress,
))
Text(
localization.withdrawalAddress,
style: theme.textTheme.titleMedium,
),
SizedBox(height: 8),
Text(
isStakeTarnsaction
? localization.stakeWithdrawalAddressText
: localization.unstakeWithdrawalAddressText,
style: theme.textTheme.bodyMedium),
SizedBox(height: 16),
WithdrawerAddress(
route: widget.routeName,
errorText: _address.error,
styledTextController: _addressController,
focusNode: _addressFocusNode,
keyboardType: TextInputType.text,
inputFormatters: [WitAddressFormatter()],
setAddressCallback: setAddress,
onChanged: (_value) => {
_addressController.text = currentAccount.address,
},
),
SizedBox(height: 4),
];
}

List<Widget> _buildValidatorAddressSelect(ThemeData theme) {
_addressController.text = currentAccount.address;
List<SelectItem> validatorAddressesUsedInStakes = [
SelectItem('validator1', 'validator1'),
SelectItem('validator2', 'validator2')
];
return [
SizedBox(height: 8),
Text(
localization.validator,
style: theme.textTheme.titleMedium,
),
SizedBox(height: 8),
Text(localization.validatorDescription,
style: theme.textTheme.bodyMedium),
SizedBox(height: 16),
Select(
selectedItem: _selectedValidator,
cropLabel: true,
listItems: validatorAddressesUsedInStakes,
onChanged: (String? label) =>
{if (label != null) setState(() => _selectedValidator = label)}),
];
}

Expand Down Expand Up @@ -568,6 +597,8 @@ class RecipientStepState extends State<RecipientStep>
crossAxisAlignment: CrossAxisAlignment.start,
children: [
..._buildAddressInput(theme),
if (isUnstakeTransaction)
..._buildValidatorAddressSelect(theme),
if (showAuthorization) ..._buildAuthorizationInput(theme),
..._buildAmountInput(theme),
],
Expand Down

0 comments on commit 351137a

Please sign in to comment.