mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
formatting, linter fixes, don't call apis in build method
This commit is contained in:
parent
f80b47d467
commit
2f0824b1f4
2 changed files with 449 additions and 453 deletions
|
@ -247,6 +247,11 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
coins = ref.read(supportedSimplexCurrenciesProvider).supportedCryptos;
|
||||
fiats = ref.read(supportedSimplexCurrenciesProvider).supportedFiats;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
BuyDataLoadingService().loadAll(
|
||||
ref); // Why does this need to be called here? Shouldn't it already be called by main.dart?
|
||||
});
|
||||
|
||||
// TODO set initial crypto to open wallet if a wallet is open
|
||||
|
||||
super.initState();
|
||||
|
@ -264,475 +269,466 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
buyWithFiat = ref.watch(
|
||||
prefsChangeNotifierProvider.select((value) => value.buyWithFiat));
|
||||
|
||||
BuyDataLoadingService().loadAll(
|
||||
ref); // Why does this need to be called here? Shouldn't it already be called by main.dart?
|
||||
|
||||
return Container(
|
||||
width:
|
||||
458, // TODO test that this displays well on mobile or else put in a ternary or something else appropriate to switch here
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
"I want to buy",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
return SizedBox(
|
||||
width:
|
||||
458, // TODO test that this displays well on mobile or else put in a ternary or something else appropriate to switch here
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
"I want to buy",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hovering1 = true),
|
||||
onExit: (_) => setState(() => _hovering1 = false),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
selectCrypto();
|
||||
},
|
||||
child: RoundedContainer(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 6, horizontal: 6),
|
||||
color: _hovering1
|
||||
? Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.highlight
|
||||
.withOpacity(_hovering1 ? 0.3 : 0)
|
||||
: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textFieldDefaultBG,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(children: <Widget>[
|
||||
SvgPicture.asset(
|
||||
Assets.svg.iconFor(
|
||||
coin: coinFromTickerCaseInsensitive("BTC"),
|
||||
),
|
||||
height: 18,
|
||||
width: 18,
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hovering1 = true),
|
||||
onExit: (_) => setState(() => _hovering1 = false),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
selectCrypto();
|
||||
},
|
||||
child: RoundedContainer(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 6),
|
||||
color: _hovering1
|
||||
? Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.highlight
|
||||
.withOpacity(_hovering1 ? 0.3 : 0)
|
||||
: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textFieldDefaultBG,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(children: <Widget>[
|
||||
SvgPicture.asset(
|
||||
Assets.svg.iconFor(
|
||||
coin: coinFromTickerCaseInsensitive("BTC"),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
"BTC",
|
||||
style: STextStyles.largeMedium14(context),
|
||||
)),
|
||||
SvgPicture.asset(
|
||||
Assets.svg.chevronDown,
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.buttonTextSecondaryDisabled,
|
||||
width: 10,
|
||||
height: 5,
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"I want to pay with",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color:
|
||||
Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
|
||||
MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hovering2 = true),
|
||||
onExit: (_) => setState(() => _hovering2 = false),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
selectFiat();
|
||||
},
|
||||
child: RoundedContainer(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 3, horizontal: 6),
|
||||
color: _hovering2
|
||||
? Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.highlight
|
||||
.withOpacity(_hovering2 ? 0.3 : 0)
|
||||
: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textFieldDefaultBG,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(children: <Widget>[
|
||||
RoundedContainer(
|
||||
radiusMultiplier: 0.5,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 2, horizontal: 4),
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.highlight,
|
||||
height: 18,
|
||||
width: 18,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
"\$",
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
),
|
||||
"BTC",
|
||||
style: STextStyles.largeMedium14(context),
|
||||
)),
|
||||
SvgPicture.asset(
|
||||
Assets.svg.chevronDown,
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.buttonTextSecondaryDisabled,
|
||||
width: 10,
|
||||
height: 5,
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"I want to pay with",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
|
||||
MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hovering2 = true),
|
||||
onExit: (_) => setState(() => _hovering2 = false),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
selectFiat();
|
||||
},
|
||||
child: RoundedContainer(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 6),
|
||||
color: _hovering2
|
||||
? Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.highlight
|
||||
.withOpacity(_hovering2 ? 0.3 : 0)
|
||||
: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textFieldDefaultBG,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(children: <Widget>[
|
||||
RoundedContainer(
|
||||
radiusMultiplier: 0.5,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 2, horizontal: 4),
|
||||
color:
|
||||
Theme.of(context).extension<StackColors>()!.highlight,
|
||||
child: Text(
|
||||
"\$",
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
),
|
||||
// SvgPicture.asset(
|
||||
// Assets.svg.iconFor(
|
||||
// coin: coinFromTickerCaseInsensitive("BTC"),
|
||||
// ),
|
||||
// height: 18,
|
||||
// width: 18,
|
||||
// ),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
"USD",
|
||||
style: STextStyles.largeMedium14(context),
|
||||
)),
|
||||
SvgPicture.asset(
|
||||
Assets.svg.chevronDown,
|
||||
),
|
||||
// SvgPicture.asset(
|
||||
// Assets.svg.iconFor(
|
||||
// coin: coinFromTickerCaseInsensitive("BTC"),
|
||||
// ),
|
||||
// height: 18,
|
||||
// width: 18,
|
||||
// ),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
"USD",
|
||||
style: STextStyles.largeMedium14(context),
|
||||
)),
|
||||
SvgPicture.asset(
|
||||
Assets.svg.chevronDown,
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.buttonTextSecondaryDisabled,
|
||||
width: 10,
|
||||
height: 5,
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
buyWithFiat ? "Enter amount" : "Enter crypto amount",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
),
|
||||
const FiatCryptoToggle(),
|
||||
],
|
||||
),
|
||||
// // these reads should be watch
|
||||
// if (ref.watch(buyFormStateProvider).fromAmount != null &&
|
||||
// ref.watch(buyFormStateProvider).fromAmount != Decimal.zero)
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
TextField(
|
||||
autocorrect: Util.isDesktop ? false : true,
|
||||
enableSuggestions: Util.isDesktop ? false : true,
|
||||
style: STextStyles.smallMed14(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark,
|
||||
),
|
||||
key: const Key("amountInputFieldCryptoTextFieldKey"),
|
||||
controller: _buyAmountController,
|
||||
focusNode: _buyAmountFocusNode,
|
||||
keyboardType: Util.isDesktop
|
||||
? null
|
||||
: const TextInputType.numberWithOptions(
|
||||
signed: false,
|
||||
decimal: true,
|
||||
),
|
||||
textAlign: TextAlign.right,
|
||||
inputFormatters: [
|
||||
// TODO reactivate formatter
|
||||
// regex to validate a crypto amount with 8 decimal places
|
||||
// TextInputFormatter.withFunction((oldValue, newValue) =>
|
||||
// RegExp(r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$')
|
||||
// .hasMatch(newValue.text)
|
||||
// ? newValue
|
||||
// : oldValue),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.only(
|
||||
top: 22,
|
||||
right: 12,
|
||||
bottom: 22,
|
||||
),
|
||||
hintText: "0",
|
||||
hintStyle: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textFieldDefaultText,
|
||||
),
|
||||
prefixIcon: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Text(
|
||||
"BTC",
|
||||
style: STextStyles.smallMed14(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.buttonTextSecondaryDisabled,
|
||||
width: 10,
|
||||
height: 5,
|
||||
),
|
||||
]),
|
||||
.accentColorDark),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
buyWithFiat ? "Enter amount" : "Enter crypto amount",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color:
|
||||
Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"Enter receiving address",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
const FiatCryptoToggle(),
|
||||
],
|
||||
),
|
||||
// // these reads should be watch
|
||||
// if (ref.watch(buyFormStateProvider).fromAmount != null &&
|
||||
// ref.watch(buyFormStateProvider).fromAmount != Decimal.zero)
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
TextField(
|
||||
autocorrect: Util.isDesktop ? false : true,
|
||||
enableSuggestions: Util.isDesktop ? false : true,
|
||||
style: STextStyles.smallMed14(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark,
|
||||
),
|
||||
key: const Key("amountInputFieldCryptoTextFieldKey"),
|
||||
controller: _buyAmountController,
|
||||
focusNode: _buyAmountFocusNode,
|
||||
keyboardType: Util.isDesktop
|
||||
? null
|
||||
: const TextInputType.numberWithOptions(
|
||||
signed: false,
|
||||
decimal: true,
|
||||
),
|
||||
textAlign: TextAlign.right,
|
||||
inputFormatters: [
|
||||
// TODO reactivate formatter
|
||||
// regex to validate a crypto amount with 8 decimal places
|
||||
// TextInputFormatter.withFunction((oldValue, newValue) =>
|
||||
// RegExp(r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$')
|
||||
// .hasMatch(newValue.text)
|
||||
// ? newValue
|
||||
// : oldValue),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(
|
||||
Constants.size.circularBorderRadius,
|
||||
),
|
||||
child: TextField(
|
||||
key: const Key("buyViewReceiveAddressFieldKey"),
|
||||
controller: _receiveAddressController,
|
||||
readOnly: false,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
// inputFormatters: <TextInputFormatter>[
|
||||
// FilteringTextInputFormatter.allow(
|
||||
// RegExp("[a-zA-Z0-9]{34}")),
|
||||
// ],
|
||||
toolbarOptions: const ToolbarOptions(
|
||||
copy: false,
|
||||
cut: false,
|
||||
paste: true,
|
||||
selectAll: false,
|
||||
),
|
||||
onChanged: (newValue) {
|
||||
_address = newValue;
|
||||
setState(() {
|
||||
_addressToggleFlag = newValue.isNotEmpty;
|
||||
});
|
||||
},
|
||||
focusNode: _receiveAddressFocusNode,
|
||||
style: STextStyles.field(context),
|
||||
decoration: standardInputDecoration(
|
||||
/*"Enter ${coin.ticker} address",*/
|
||||
"Enter address",
|
||||
_receiveAddressFocusNode,
|
||||
context,
|
||||
).copyWith(
|
||||
contentPadding: const EdgeInsets.only(
|
||||
top: 22,
|
||||
right: 12,
|
||||
bottom: 22,
|
||||
left: 16,
|
||||
top: 6,
|
||||
bottom: 8,
|
||||
right: 5,
|
||||
),
|
||||
hintText: "0",
|
||||
hintStyle: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textFieldDefaultText,
|
||||
),
|
||||
prefixIcon: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Text(
|
||||
"BTC",
|
||||
style: STextStyles.smallMed14(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.accentColorDark),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"Enter receiving address",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color:
|
||||
Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 10 : 4,
|
||||
),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(
|
||||
Constants.size.circularBorderRadius,
|
||||
),
|
||||
child: TextField(
|
||||
key: const Key("buyViewReceiveAddressFieldKey"),
|
||||
controller: _receiveAddressController,
|
||||
readOnly: false,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
// inputFormatters: <TextInputFormatter>[
|
||||
// FilteringTextInputFormatter.allow(
|
||||
// RegExp("[a-zA-Z0-9]{34}")),
|
||||
// ],
|
||||
toolbarOptions: const ToolbarOptions(
|
||||
copy: false,
|
||||
cut: false,
|
||||
paste: true,
|
||||
selectAll: false,
|
||||
),
|
||||
onChanged: (newValue) {
|
||||
_address = newValue;
|
||||
setState(() {
|
||||
_addressToggleFlag = newValue.isNotEmpty;
|
||||
});
|
||||
},
|
||||
focusNode: _receiveAddressFocusNode,
|
||||
style: STextStyles.field(context),
|
||||
decoration: standardInputDecoration(
|
||||
/*"Enter ${coin.ticker} address",*/
|
||||
"Enter address",
|
||||
_receiveAddressFocusNode,
|
||||
context,
|
||||
).copyWith(
|
||||
contentPadding: const EdgeInsets.only(
|
||||
left: 16,
|
||||
top: 6,
|
||||
bottom: 8,
|
||||
right: 5,
|
||||
),
|
||||
suffixIcon: Padding(
|
||||
padding: _receiveAddressController.text.isEmpty
|
||||
? const EdgeInsets.only(right: 8)
|
||||
: const EdgeInsets.only(right: 0),
|
||||
child: UnconstrainedBox(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_addressToggleFlag
|
||||
? TextFieldIconButton(
|
||||
key: const Key(
|
||||
"buyViewClearAddressFieldButtonKey"),
|
||||
onTap: () {
|
||||
_receiveAddressController.text = "";
|
||||
// _receiveAddress = "";
|
||||
setState(() {
|
||||
_addressToggleFlag = false;
|
||||
});
|
||||
},
|
||||
child: const XIcon(),
|
||||
)
|
||||
: TextFieldIconButton(
|
||||
key: const Key(
|
||||
"buyViewPasteAddressFieldButtonKey"),
|
||||
onTap: () async {
|
||||
print(
|
||||
"TODO paste; Error: 'ClipboardData' isn't a type.");
|
||||
// final ClipboardData? data = await clipboard
|
||||
// .getData(Clipboard.kTextPlain);
|
||||
// if (data?.text != null &&
|
||||
// data!.text!.isNotEmpty) {
|
||||
// String content = data.text!.trim();
|
||||
// if (content.contains("\n")) {
|
||||
// content = content.substring(
|
||||
// 0, content.indexOf("\n"));
|
||||
// }
|
||||
//
|
||||
// _receiveAddressController.text = content;
|
||||
// _address = content;
|
||||
//
|
||||
// setState(() {
|
||||
// _addressToggleFlag =
|
||||
// _receiveAddressController
|
||||
// .text.isNotEmpty;
|
||||
// });
|
||||
// }
|
||||
},
|
||||
child: _receiveAddressController.text.isEmpty
|
||||
? const ClipboardIcon()
|
||||
: const XIcon(),
|
||||
),
|
||||
if (_receiveAddressController.text.isEmpty)
|
||||
TextFieldIconButton(
|
||||
key: const Key("buyViewAddressBookButtonKey"),
|
||||
onTap: () {
|
||||
print(
|
||||
'TODO tapped buyViewAddressBookButtonKey');
|
||||
// Navigator.of(context).pushNamed(
|
||||
// AddressBookView.routeName,
|
||||
// arguments: widget.coin,
|
||||
// );
|
||||
},
|
||||
child: const AddressBookIcon(),
|
||||
),
|
||||
if (_receiveAddressController.text.isEmpty &&
|
||||
!isDesktop)
|
||||
TextFieldIconButton(
|
||||
key: const Key("buyViewScanQrButtonKey"),
|
||||
onTap: () async {
|
||||
try {
|
||||
// ref
|
||||
// .read(
|
||||
// shouldShowLockscreenOnResumeStateProvider
|
||||
// .state)
|
||||
// .state = false;
|
||||
if (FocusScope.of(context).hasFocus) {
|
||||
FocusScope.of(context).unfocus();
|
||||
await Future<void>.delayed(
|
||||
const Duration(milliseconds: 75));
|
||||
}
|
||||
|
||||
final qrResult = await scanner.scan();
|
||||
|
||||
Logging.instance.log(
|
||||
"qrResult content: ${qrResult.rawContent}",
|
||||
level: LogLevel.Info);
|
||||
|
||||
final results = AddressUtils.parseUri(
|
||||
qrResult.rawContent);
|
||||
|
||||
Logging.instance.log(
|
||||
"qrResult parsed: $results",
|
||||
level: LogLevel.Info);
|
||||
|
||||
print('TODO implement QR scanning');
|
||||
// if (results.isNotEmpty &&
|
||||
// results["scheme"] == coin.uriScheme) {
|
||||
// // auto fill address
|
||||
// _address = results["address"] ?? "";
|
||||
// sendToController.text = _address!;
|
||||
//
|
||||
// // autofill notes field
|
||||
// if (results["message"] != null) {
|
||||
// noteController.text = results["message"]!;
|
||||
// } else if (results["label"] != null) {
|
||||
// noteController.text = results["label"]!;
|
||||
suffixIcon: Padding(
|
||||
padding: _receiveAddressController.text.isEmpty
|
||||
? const EdgeInsets.only(right: 8)
|
||||
: const EdgeInsets.only(right: 0),
|
||||
child: UnconstrainedBox(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_addressToggleFlag
|
||||
? TextFieldIconButton(
|
||||
key: const Key(
|
||||
"buyViewClearAddressFieldButtonKey"),
|
||||
onTap: () {
|
||||
_receiveAddressController.text = "";
|
||||
// _receiveAddress = "";
|
||||
setState(() {
|
||||
_addressToggleFlag = false;
|
||||
});
|
||||
},
|
||||
child: const XIcon(),
|
||||
)
|
||||
: TextFieldIconButton(
|
||||
key: const Key(
|
||||
"buyViewPasteAddressFieldButtonKey"),
|
||||
onTap: () async {
|
||||
print(
|
||||
"TODO paste; Error: 'ClipboardData' isn't a type.");
|
||||
// final ClipboardData? data = await clipboard
|
||||
// .getData(Clipboard.kTextPlain);
|
||||
// if (data?.text != null &&
|
||||
// data!.text!.isNotEmpty) {
|
||||
// String content = data.text!.trim();
|
||||
// if (content.contains("\n")) {
|
||||
// content = content.substring(
|
||||
// 0, content.indexOf("\n"));
|
||||
// }
|
||||
//
|
||||
// // autofill amount field
|
||||
// if (results["amount"] != null) {
|
||||
// final amount =
|
||||
// Decimal.parse(results["amount"]!);
|
||||
// cryptoAmountController.text =
|
||||
// Format.localizedStringAsFixed(
|
||||
// value: amount,
|
||||
// locale: ref
|
||||
// .read(
|
||||
// localeServiceChangeNotifierProvider)
|
||||
// .locale,
|
||||
// decimalPlaces:
|
||||
// Constants.decimalPlacesForCoin(
|
||||
// coin),
|
||||
// );
|
||||
// amount.toString();
|
||||
// _amountToSend = amount;
|
||||
// }
|
||||
// _receiveAddressController.text = content;
|
||||
// _address = content;
|
||||
//
|
||||
// _updatePreviewButtonState(
|
||||
// _address, _amountToSend);
|
||||
// setState(() {
|
||||
// _addressToggleFlag =
|
||||
// sendToController.text.isNotEmpty;
|
||||
// });
|
||||
//
|
||||
// // now check for non standard encoded basic address
|
||||
// } else if (ref
|
||||
// .read(walletsChangeNotifierProvider)
|
||||
// .getManager(walletId)
|
||||
// .validateAddress(qrResult.rawContent)) {
|
||||
// _address = qrResult.rawContent;
|
||||
// sendToController.text = _address ?? "";
|
||||
//
|
||||
// _updatePreviewButtonState(
|
||||
// _address, _amountToSend);
|
||||
// setState(() {
|
||||
// _addressToggleFlag =
|
||||
// sendToController.text.isNotEmpty;
|
||||
// _receiveAddressController
|
||||
// .text.isNotEmpty;
|
||||
// });
|
||||
// }
|
||||
} /*on PlatformException*/ catch (e, s) {
|
||||
// ref
|
||||
// .read(
|
||||
// shouldShowLockscreenOnResumeStateProvider
|
||||
// .state)
|
||||
// .state = true;
|
||||
// here we ignore the exception caused by not giving permission
|
||||
// to use the camera to scan a qr code
|
||||
Logging.instance.log(
|
||||
"Failed to get camera permissions while trying to scan qr code in SendView: $e\n$s",
|
||||
level: LogLevel.Warning);
|
||||
},
|
||||
child: _receiveAddressController.text.isEmpty
|
||||
? const ClipboardIcon()
|
||||
: const XIcon(),
|
||||
),
|
||||
if (_receiveAddressController.text.isEmpty)
|
||||
TextFieldIconButton(
|
||||
key: const Key("buyViewAddressBookButtonKey"),
|
||||
onTap: () {
|
||||
print('TODO tapped buyViewAddressBookButtonKey');
|
||||
// Navigator.of(context).pushNamed(
|
||||
// AddressBookView.routeName,
|
||||
// arguments: widget.coin,
|
||||
// );
|
||||
},
|
||||
child: const AddressBookIcon(),
|
||||
),
|
||||
if (_receiveAddressController.text.isEmpty &&
|
||||
!isDesktop)
|
||||
TextFieldIconButton(
|
||||
key: const Key("buyViewScanQrButtonKey"),
|
||||
onTap: () async {
|
||||
try {
|
||||
// ref
|
||||
// .read(
|
||||
// shouldShowLockscreenOnResumeStateProvider
|
||||
// .state)
|
||||
// .state = false;
|
||||
if (FocusScope.of(context).hasFocus) {
|
||||
FocusScope.of(context).unfocus();
|
||||
await Future<void>.delayed(
|
||||
const Duration(milliseconds: 75));
|
||||
}
|
||||
},
|
||||
child: const QrCodeIcon(),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
final qrResult = await scanner.scan();
|
||||
|
||||
Logging.instance.log(
|
||||
"qrResult content: ${qrResult.rawContent}",
|
||||
level: LogLevel.Info);
|
||||
|
||||
final results =
|
||||
AddressUtils.parseUri(qrResult.rawContent);
|
||||
|
||||
Logging.instance.log(
|
||||
"qrResult parsed: $results",
|
||||
level: LogLevel.Info);
|
||||
|
||||
print('TODO implement QR scanning');
|
||||
// if (results.isNotEmpty &&
|
||||
// results["scheme"] == coin.uriScheme) {
|
||||
// // auto fill address
|
||||
// _address = results["address"] ?? "";
|
||||
// sendToController.text = _address!;
|
||||
//
|
||||
// // autofill notes field
|
||||
// if (results["message"] != null) {
|
||||
// noteController.text = results["message"]!;
|
||||
// } else if (results["label"] != null) {
|
||||
// noteController.text = results["label"]!;
|
||||
// }
|
||||
//
|
||||
// // autofill amount field
|
||||
// if (results["amount"] != null) {
|
||||
// final amount =
|
||||
// Decimal.parse(results["amount"]!);
|
||||
// cryptoAmountController.text =
|
||||
// Format.localizedStringAsFixed(
|
||||
// value: amount,
|
||||
// locale: ref
|
||||
// .read(
|
||||
// localeServiceChangeNotifierProvider)
|
||||
// .locale,
|
||||
// decimalPlaces:
|
||||
// Constants.decimalPlacesForCoin(
|
||||
// coin),
|
||||
// );
|
||||
// amount.toString();
|
||||
// _amountToSend = amount;
|
||||
// }
|
||||
//
|
||||
// _updatePreviewButtonState(
|
||||
// _address, _amountToSend);
|
||||
// setState(() {
|
||||
// _addressToggleFlag =
|
||||
// sendToController.text.isNotEmpty;
|
||||
// });
|
||||
//
|
||||
// // now check for non standard encoded basic address
|
||||
// } else if (ref
|
||||
// .read(walletsChangeNotifierProvider)
|
||||
// .getManager(walletId)
|
||||
// .validateAddress(qrResult.rawContent)) {
|
||||
// _address = qrResult.rawContent;
|
||||
// sendToController.text = _address ?? "";
|
||||
//
|
||||
// _updatePreviewButtonState(
|
||||
// _address, _amountToSend);
|
||||
// setState(() {
|
||||
// _addressToggleFlag =
|
||||
// sendToController.text.isNotEmpty;
|
||||
// });
|
||||
// }
|
||||
} /*on PlatformException*/ catch (e, s) {
|
||||
// ref
|
||||
// .read(
|
||||
// shouldShowLockscreenOnResumeStateProvider
|
||||
// .state)
|
||||
// .state = true;
|
||||
// here we ignore the exception caused by not giving permission
|
||||
// to use the camera to scan a qr code
|
||||
Logging.instance.log(
|
||||
"Failed to get camera permissions while trying to scan qr code in SendView: $e\n$s",
|
||||
level: LogLevel.Warning);
|
||||
}
|
||||
},
|
||||
child: const QrCodeIcon(),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
PrimaryButton(
|
||||
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
||||
enabled: ref.watch(exchangeFormStateProvider
|
||||
.select((value) => value.canExchange)),
|
||||
onPressed: () {
|
||||
// TODO implement buy confirmation dialog
|
||||
},
|
||||
label: "Exchange",
|
||||
)
|
||||
],
|
||||
));
|
||||
),
|
||||
SizedBox(
|
||||
height: isDesktop ? 20 : 12,
|
||||
),
|
||||
PrimaryButton(
|
||||
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
||||
enabled: ref.watch(
|
||||
exchangeFormStateProvider.select((value) => value.canExchange)),
|
||||
onPressed: () {
|
||||
// TODO implement buy confirmation dialog
|
||||
},
|
||||
label: "Exchange",
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,17 +11,17 @@ class BuyView extends StatefulWidget {
|
|||
class _BuyViewState extends State<BuyView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//todo: check if print needed
|
||||
// debugPrint("BUILD: BuyView");
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
return const SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
),
|
||||
child: BuyForm(),
|
||||
),
|
||||
child: BuyForm(),
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue