CAKE-116 | added AllAmountValidator class to the amount_validator.dart; applied all amount validator to the send page; added fiat amount controller to the send page

OleksandrSobol committed Oct 9, 2020 at 10:41 UTC 0b6b7116186853ce69ae947654c50b287985dc22
3 files changed +80 -58
lib/core/amount_validator.dart
+8
@@ -23,3 +23,11 @@ class AmountValidator extends TextValidator {
23 }
24 }
25 }
26 +
27 +class AllAmountValidator extends TextValidator {
28 + AllAmountValidator() : super(
29 + errorMessage: S.current.error_text_amount,
30 + pattern: S.current.all,
31 + minLength: 0,
32 + maxLength: 0);
33 +}
lib/src/screens/send/send_page.dart
+70 -58
@@ -161,70 +161,73 @@ class SendPage extends BasePage {
161 .decorationColor),
162 validator: sendViewModel.addressValidator,
163 ),
164 - Padding(
165 - padding: const EdgeInsets.only(top: 20),
166 - child: BaseTextFormField(
167 - focusNode: _cryptoAmountFocus,
168 - controller: _cryptoAmountController,
169 - keyboardType:
164 + Observer(
165 + builder: (_) => Padding(
166 + padding: const EdgeInsets.only(top: 20),
167 + child: BaseTextFormField(
168 + focusNode: _cryptoAmountFocus,
169 + controller: _cryptoAmountController,
170 + keyboardType:
171 TextInputType.numberWithOptions(
172 signed: false, decimal: true),
172 - prefixIcon: Padding(
173 - padding: EdgeInsets.only(top: 9),
174 - child: Text(
175 - sendViewModel.currency.title + ':',
176 - style: TextStyle(
177 - fontSize: 16,
178 - fontWeight: FontWeight.w600,
179 - color: Colors.white,
180 - )),
181 - ),
182 - suffixIcon: Container(
183 - height: 32,
184 - width: 32,
185 - margin: EdgeInsets.only(
186 - left: 14, top: 4, bottom: 10),
187 - decoration: BoxDecoration(
188 - color: Theme.of(context)
189 - .primaryTextTheme
190 - .display1
191 - .color,
192 - borderRadius: BorderRadius.all(
193 - Radius.circular(6))),
194 - child: InkWell(
195 - onTap: () =>
196 - sendViewModel.setSendAll(),
197 - child: Center(
198 - child: Text(S.of(context).all,
199 - textAlign: TextAlign.center,
173 + prefixIcon: Padding(
174 + padding: EdgeInsets.only(top: 9),
175 + child: Text(
176 + sendViewModel.currency.title + ':',
177 style: TextStyle(
201 - fontSize: 12,
202 - fontWeight: FontWeight.bold,
203 - color: Theme.of(context)
204 - .primaryTextTheme
205 - .display1
206 - .decorationColor)),
178 + fontSize: 16,
179 + fontWeight: FontWeight.w600,
180 + color: Colors.white,
181 + )),
182 ),
208 - ),
209 - ),
210 - hintText: '0.0000',
211 - borderColor: Theme.of(context)
212 - .primaryTextTheme
213 - .headline
214 - .color,
215 - textStyle: TextStyle(
216 - fontSize: 14,
217 - fontWeight: FontWeight.w500,
218 - color: Colors.white),
219 - placeholderTextStyle: TextStyle(
220 - color: Theme.of(context)
183 + suffixIcon: Container(
184 + height: 32,
185 + width: 32,
186 + margin: EdgeInsets.only(
187 + left: 14, top: 4, bottom: 10),
188 + decoration: BoxDecoration(
189 + color: Theme.of(context)
190 + .primaryTextTheme
191 + .display1
192 + .color,
193 + borderRadius: BorderRadius.all(
194 + Radius.circular(6))),
195 + child: InkWell(
196 + onTap: () =>
197 + sendViewModel.setSendAll(),
198 + child: Center(
199 + child: Text(S.of(context).all,
200 + textAlign: TextAlign.center,
201 + style: TextStyle(
202 + fontSize: 12,
203 + fontWeight: FontWeight.bold,
204 + color: Theme.of(context)
205 + .primaryTextTheme
206 + .display1
207 + .decorationColor)),
208 + ),
209 + ),
210 + ),
211 + hintText: '0.0000',
212 + borderColor: Theme.of(context)
213 .primaryTextTheme
214 .headline
223 - .decorationColor,
224 - fontWeight: FontWeight.w500,
225 - fontSize: 14),
226 - validator:
227 - sendViewModel.amountValidator)),
215 + .color,
216 + textStyle: TextStyle(
217 + fontSize: 14,
218 + fontWeight: FontWeight.w500,
219 + color: Colors.white),
220 + placeholderTextStyle: TextStyle(
221 + color: Theme.of(context)
222 + .primaryTextTheme
223 + .headline
224 + .decorationColor,
225 + fontWeight: FontWeight.w500,
226 + fontSize: 14),
227 + validator:
228 + sendViewModel.sendAll
229 + ? sendViewModel.allAmountValidator
230 + : sendViewModel.amountValidator))),
231 Observer(
232 builder: (_) => Padding(
233 padding: EdgeInsets.only(top: 10),
@@ -507,6 +510,15 @@ class SendPage extends BasePage {
510 }
511 });
512
513 + _fiatAmountController.addListener(() {
514 + final amount = _fiatAmountController.text;
515 +
516 + if (amount != sendViewModel.fiatAmount) {
517 + sendViewModel.sendAll = false;
518 + sendViewModel.setFiatAmount(amount);
519 + }
520 + });
521 +
522 reaction((_) => sendViewModel.sendAll, (bool all) {
523 if (all) {
524 _cryptoAmountController.text = S.current.all;
lib/view_model/send/send_view_model.dart
+2
@@ -64,6 +64,8 @@ abstract class SendViewModelBase with Store {
64
65 Validator get amountValidator => AmountValidator(type: _wallet.type);
66
67 + Validator get allAmountValidator => AllAmountValidator();
68 +
69 Validator get addressValidator => AddressValidator(type: _wallet.currency);
70
71 Validator get templateValidator => TemplateValidator();