2020-01-08 12:26:34 +00:00
|
|
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:cake_wallet/palette.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/address_text_field.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/balance/balance_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/send/send_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/send/sending_state.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/sync/sync_store.dart';
|
2020-05-07 17:10:04 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/top_panel.dart';
|
|
|
|
import 'package:dotted_border/dotted_border.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/sending_alert.dart';
|
2020-05-08 16:22:56 +00:00
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/template_tile.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/send_template/send_template_store.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class SendPage extends BasePage {
|
2020-01-08 12:26:34 +00:00
|
|
|
@override
|
2020-01-04 19:31:52 +00:00
|
|
|
String get title => S.current.send_title;
|
2020-01-08 12:26:34 +00:00
|
|
|
|
|
|
|
@override
|
2020-05-07 17:10:04 +00:00
|
|
|
Color get backgroundColor => PaletteDark.menuList;
|
2020-01-08 12:26:34 +00:00
|
|
|
|
|
|
|
@override
|
2020-01-04 19:31:52 +00:00
|
|
|
bool get resizeToAvoidBottomPadding => false;
|
|
|
|
|
2020-05-11 08:22:03 +00:00
|
|
|
@override
|
|
|
|
Widget trailing(context) {
|
|
|
|
final sendStore = Provider.of<SendStore>(context);
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
height: 32,
|
|
|
|
width: 82,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(16)),
|
|
|
|
color: PaletteDark.menuHeader
|
|
|
|
),
|
|
|
|
child: ButtonTheme(
|
|
|
|
minWidth: double.minPositive,
|
|
|
|
child: FlatButton(
|
|
|
|
onPressed: () => sendStore.clear(),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).clear,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10.0,
|
|
|
|
color: Colors.blue),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) => SendForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SendForm extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => SendFormState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SendFormState extends State<SendForm> {
|
|
|
|
final _addressController = TextEditingController();
|
|
|
|
final _cryptoAmountController = TextEditingController();
|
|
|
|
final _fiatAmountController = TextEditingController();
|
|
|
|
|
2020-02-20 20:50:22 +00:00
|
|
|
final _focusNode = FocusNode();
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
bool _effectsInstalled = false;
|
|
|
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
2020-02-20 20:50:22 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2020-02-25 09:28:33 +00:00
|
|
|
_focusNode.addListener(() {
|
2020-02-20 21:02:41 +00:00
|
|
|
if (!_focusNode.hasFocus &&_addressController.text.isNotEmpty) {
|
2020-02-25 09:28:33 +00:00
|
|
|
getOpenaliasRecord(context);
|
2020-02-20 20:50:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
Future<void> getOpenaliasRecord(BuildContext context) async {
|
2020-02-25 09:28:33 +00:00
|
|
|
final sendStore = Provider.of<SendStore>(context);
|
|
|
|
final isOpenalias = await sendStore.isOpenaliasRecord(_addressController.text);
|
|
|
|
|
|
|
|
if (isOpenalias) {
|
|
|
|
_addressController.text = sendStore.recordAddress;
|
|
|
|
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2020-05-07 17:10:04 +00:00
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).openalias_alert_title,
|
|
|
|
alertContent: S.of(context).openalias_alert_content(sendStore.recordName),
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop()
|
2020-02-25 09:28:33 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final settingsStore = Provider.of<SettingsStore>(context);
|
|
|
|
final sendStore = Provider.of<SendStore>(context);
|
|
|
|
sendStore.settingsStore = settingsStore;
|
|
|
|
final balanceStore = Provider.of<BalanceStore>(context);
|
|
|
|
final walletStore = Provider.of<WalletStore>(context);
|
|
|
|
final syncStore = Provider.of<SyncStore>(context);
|
2020-05-08 16:22:56 +00:00
|
|
|
final sendTemplateStore = Provider.of<SendTemplateStore>(context);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
_setEffects(context);
|
|
|
|
|
2020-05-07 17:10:04 +00:00
|
|
|
return Container(
|
|
|
|
color: PaletteDark.historyPanel,
|
|
|
|
child: ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.only(bottom: 24),
|
2020-01-04 19:31:52 +00:00
|
|
|
content: Column(
|
2020-05-07 17:10:04 +00:00
|
|
|
children: <Widget>[
|
|
|
|
TopPanel(
|
|
|
|
color: PaletteDark.menuList,
|
|
|
|
widget: Form(
|
|
|
|
key: _formKey,
|
2020-01-04 19:31:52 +00:00
|
|
|
child: Column(children: <Widget>[
|
|
|
|
AddressTextField(
|
|
|
|
controller: _addressController,
|
|
|
|
placeholder: S.of(context).send_monero_address,
|
2020-02-20 20:50:22 +00:00
|
|
|
focusNode: _focusNode,
|
2020-01-04 19:31:52 +00:00
|
|
|
onURIScanned: (uri) {
|
|
|
|
var address = '';
|
|
|
|
var amount = '';
|
|
|
|
|
|
|
|
if (uri != null) {
|
|
|
|
address = uri.path;
|
|
|
|
amount = uri.queryParameters['tx_amount'];
|
|
|
|
} else {
|
|
|
|
address = uri.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
_addressController.text = address;
|
|
|
|
_cryptoAmountController.text = amount;
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
AddressTextFieldOption.qrCode,
|
|
|
|
AddressTextFieldOption.addressBook
|
|
|
|
],
|
|
|
|
validator: (value) {
|
|
|
|
sendStore.validateAddress(value,
|
|
|
|
cryptoCurrency: CryptoCurrency.xmr);
|
|
|
|
return sendStore.errorMessage;
|
|
|
|
},
|
|
|
|
),
|
2020-05-07 17:10:04 +00:00
|
|
|
Observer(
|
|
|
|
builder: (_) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: TextFormField(
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
|
|
|
color: Colors.white
|
2020-01-04 19:31:52 +00:00
|
|
|
),
|
2020-05-07 17:10:04 +00:00
|
|
|
controller: _cryptoAmountController,
|
|
|
|
keyboardType: TextInputType.numberWithOptions(
|
|
|
|
signed: false, decimal: true),
|
|
|
|
inputFormatters: [
|
|
|
|
BlacklistingTextInputFormatter(
|
|
|
|
RegExp('[\\-|\\ |\\,]'))
|
|
|
|
],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: EdgeInsets.only(top: 12),
|
|
|
|
child: Text('XMR:',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.white,
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
suffixIcon: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: 5
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
width: MediaQuery.of(context).size.width/2,
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
' / ' + balanceStore.unlockedBalance,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
color: PaletteDark.walletCardText
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 32,
|
|
|
|
width: 32,
|
|
|
|
margin: EdgeInsets.only(left: 12, bottom: 7, top: 4),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: PaletteDark.walletCardSubAddressField,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(6))
|
|
|
|
),
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => sendStore.setSendAll(),
|
|
|
|
child: Center(
|
|
|
|
child: Text(S.of(context).all,
|
2020-05-11 08:22:03 +00:00
|
|
|
textAlign: TextAlign.center,
|
2020-05-07 17:10:04 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 9,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: PaletteDark.walletCardText
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 16.0,
|
|
|
|
color: Colors.white),
|
|
|
|
hintText: '0.0000',
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: PaletteDark.walletCardSubAddressField,
|
|
|
|
width: 1.0)),
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: PaletteDark.walletCardSubAddressField,
|
|
|
|
width: 1.0))),
|
|
|
|
validator: (value) {
|
|
|
|
sendStore.validateXMR(
|
|
|
|
value, balanceStore.unlockedBalance);
|
|
|
|
return sendStore.errorMessage;
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: TextFormField(
|
|
|
|
style: TextStyle(
|
2020-05-07 17:10:04 +00:00
|
|
|
fontSize: 16.0,
|
|
|
|
color: Colors.white),
|
2020-01-04 19:31:52 +00:00
|
|
|
controller: _fiatAmountController,
|
|
|
|
keyboardType: TextInputType.numberWithOptions(
|
2020-01-22 16:42:11 +00:00
|
|
|
signed: false, decimal: true),
|
2020-01-04 19:31:52 +00:00
|
|
|
inputFormatters: [
|
|
|
|
BlacklistingTextInputFormatter(
|
2020-01-08 12:26:34 +00:00
|
|
|
RegExp('[\\-|\\ |\\,]'))
|
2020-01-04 19:31:52 +00:00
|
|
|
],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: EdgeInsets.only(top: 12),
|
|
|
|
child: Text(
|
|
|
|
'${settingsStore.fiatCurrency.toString()}:',
|
|
|
|
style: TextStyle(
|
2020-05-07 17:10:04 +00:00
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.white,
|
2020-01-04 19:31:52 +00:00
|
|
|
)),
|
|
|
|
),
|
|
|
|
hintStyle: TextStyle(
|
2020-05-07 17:10:04 +00:00
|
|
|
fontSize: 16.0,
|
|
|
|
color: PaletteDark.walletCardText),
|
2020-01-04 19:31:52 +00:00
|
|
|
hintText: '0.00',
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
2020-05-07 17:10:04 +00:00
|
|
|
color: PaletteDark.walletCardSubAddressField,
|
|
|
|
width: 1.0)),
|
2020-01-04 19:31:52 +00:00
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
2020-05-07 17:10:04 +00:00
|
|
|
color: PaletteDark.walletCardSubAddressField,
|
2020-01-04 19:31:52 +00:00
|
|
|
width: 1.0)))),
|
|
|
|
),
|
2020-05-11 08:22:03 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(S.of(context).send_estimated_fee,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Colors.white,
|
|
|
|
)),
|
|
|
|
Text(
|
|
|
|
'${calculateEstimatedFee(priority: settingsStore.transactionPriority)} XMR',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Colors.white,
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
2020-01-04 19:31:52 +00:00
|
|
|
]),
|
|
|
|
),
|
2020-05-07 17:10:04 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: 32,
|
|
|
|
left: 24,
|
|
|
|
bottom: 24
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
2020-05-08 16:22:56 +00:00
|
|
|
S.of(context).send_templates,
|
2020-05-07 17:10:04 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: PaletteDark.walletCardText
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 40,
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.only(left: 24),
|
2020-05-08 16:22:56 +00:00
|
|
|
child: Observer(
|
|
|
|
builder: (_) {
|
|
|
|
final itemCount = sendTemplateStore.templates.length + 1;
|
|
|
|
|
|
|
|
return ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: itemCount,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () => Navigator.of(context)
|
|
|
|
.pushNamed(Routes.sendTemplate, arguments: sendStore),
|
2020-05-07 17:10:04 +00:00
|
|
|
child: Container(
|
2020-05-08 16:22:56 +00:00
|
|
|
padding: EdgeInsets.only(right: 10),
|
|
|
|
child: DottedBorder(
|
|
|
|
borderType: BorderType.RRect,
|
|
|
|
dashPattern: [8, 4],
|
|
|
|
color: PaletteDark.menuList,
|
|
|
|
strokeWidth: 2,
|
|
|
|
radius: Radius.circular(20),
|
|
|
|
child: Container(
|
|
|
|
height: 40,
|
|
|
|
width: 75,
|
|
|
|
padding: EdgeInsets.only(left: 10, right: 10),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(20)),
|
|
|
|
color: Colors.transparent,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).send_new,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: PaletteDark.walletCardText
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2020-05-07 17:10:04 +00:00
|
|
|
),
|
2020-05-08 16:22:56 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
index -= 1;
|
|
|
|
|
|
|
|
final template = sendTemplateStore.templates[index];
|
2020-05-07 17:10:04 +00:00
|
|
|
|
2020-05-08 16:22:56 +00:00
|
|
|
return TemplateTile(
|
|
|
|
name: template.name,
|
|
|
|
amount: template.amount,
|
|
|
|
cryptoCurrency: template.cryptoCurrency,
|
|
|
|
onTap: () {
|
|
|
|
_addressController.text = template.address;
|
|
|
|
_cryptoAmountController.text = template.amount;
|
|
|
|
getOpenaliasRecord(context);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-05-07 17:10:04 +00:00
|
|
|
),
|
2020-01-04 19:31:52 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-05-07 17:10:04 +00:00
|
|
|
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
2020-01-04 19:31:52 +00:00
|
|
|
bottomSection: Observer(builder: (_) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: syncStore.status is SyncedSyncStatus
|
|
|
|
? () async {
|
2020-05-07 17:10:04 +00:00
|
|
|
// Hack. Don't ask me.
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
|
|
|
|
if (_formKey.currentState.validate()) {
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (dialogContext) {
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
alertTitle: S.of(context).send_creating_transaction,
|
|
|
|
alertContent: S.of(context).confirm_sending,
|
|
|
|
leftButtonText: S.of(context).send,
|
|
|
|
rightButtonText: S.of(context).cancel,
|
|
|
|
actionLeftButton: () async {
|
|
|
|
await Navigator.of(dialogContext)
|
|
|
|
.popAndPushNamed(Routes.auth,
|
|
|
|
arguments: (bool
|
|
|
|
isAuthenticatedSuccessfully,
|
|
|
|
AuthPageState auth) {
|
|
|
|
if (!isAuthenticatedSuccessfully) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Navigator.of(auth.context).pop();
|
|
|
|
|
|
|
|
sendStore.createTransaction(
|
|
|
|
address: _addressController.text,
|
|
|
|
paymentId: '');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
actionRightButton: () =>
|
|
|
|
Navigator.of(context).pop()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: null,
|
2020-01-04 19:31:52 +00:00
|
|
|
text: S.of(context).send,
|
2020-05-07 17:10:04 +00:00
|
|
|
color: Colors.blue,
|
|
|
|
textColor: Colors.white,
|
2020-01-04 19:31:52 +00:00
|
|
|
isLoading: sendStore.state is CreatingTransaction ||
|
2020-05-07 17:10:04 +00:00
|
|
|
sendStore.state is TransactionCommiting,
|
|
|
|
isDisabled: !(syncStore.status is SyncedSyncStatus),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _setEffects(BuildContext context) {
|
|
|
|
if (_effectsInstalled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final sendStore = Provider.of<SendStore>(context);
|
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
reaction((_) => sendStore.fiatAmount, (String amount) {
|
2020-01-04 19:31:52 +00:00
|
|
|
if (amount != _fiatAmountController.text) {
|
|
|
|
_fiatAmountController.text = amount;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
reaction((_) => sendStore.cryptoAmount, (String amount) {
|
2020-01-04 19:31:52 +00:00
|
|
|
if (amount != _cryptoAmountController.text) {
|
|
|
|
_cryptoAmountController.text = amount;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-11 08:22:03 +00:00
|
|
|
reaction((_) => sendStore.address, (String address) {
|
|
|
|
if (address != _addressController.text) {
|
|
|
|
_addressController.text = address;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_addressController.addListener(() {
|
|
|
|
final address = _addressController.text;
|
|
|
|
|
|
|
|
if (sendStore.address != address) {
|
|
|
|
sendStore.changeAddress(address);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
_fiatAmountController.addListener(() {
|
|
|
|
final fiatAmount = _fiatAmountController.text;
|
|
|
|
|
|
|
|
if (sendStore.fiatAmount != fiatAmount) {
|
|
|
|
sendStore.changeFiatAmount(fiatAmount);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_cryptoAmountController.addListener(() {
|
|
|
|
final cryptoAmount = _cryptoAmountController.text;
|
|
|
|
|
|
|
|
if (sendStore.cryptoAmount != cryptoAmount) {
|
|
|
|
sendStore.changeCryptoAmount(cryptoAmount);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
reaction((_) => sendStore.state, (SendingState state) {
|
2020-01-04 19:31:52 +00:00
|
|
|
if (state is SendingFailed) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-01-08 12:26:34 +00:00
|
|
|
showDialog<void>(
|
2020-01-04 19:31:52 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2020-05-07 17:10:04 +00:00
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).error,
|
|
|
|
alertContent: state.error,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop()
|
2020-01-04 19:31:52 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is TransactionCreatedSuccessfully) {
|
2020-01-13 12:34:50 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2020-05-07 17:10:04 +00:00
|
|
|
return ConfirmSendingAlert(
|
|
|
|
alertTitle: S.of(context).confirm_sending,
|
2020-05-08 16:22:56 +00:00
|
|
|
amount: S.of(context).send_amount,
|
2020-05-07 17:10:04 +00:00
|
|
|
amountValue: sendStore.pendingTransaction.amount,
|
2020-05-08 16:22:56 +00:00
|
|
|
fee: S.of(context).send_fee,
|
2020-05-07 17:10:04 +00:00
|
|
|
feeValue: sendStore.pendingTransaction.fee,
|
|
|
|
leftButtonText: S.of(context).ok,
|
|
|
|
rightButtonText: S.of(context).cancel,
|
|
|
|
actionLeftButton: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
sendStore.commitTransaction();
|
|
|
|
showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return SendingAlert(sendStore: sendStore);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
actionRightButton: () => Navigator.of(context).pop()
|
2020-01-13 12:34:50 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is TransactionCommitted) {
|
2020-01-04 19:31:52 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-05-07 17:10:04 +00:00
|
|
|
_addressController.text = '';
|
|
|
|
_cryptoAmountController.text = '';
|
2020-01-04 19:31:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_effectsInstalled = true;
|
|
|
|
}
|
|
|
|
}
|