async hasConnected ui update

This commit is contained in:
julian 2023-01-23 15:39:05 -06:00
parent 5eb4b3bff5
commit 8a7d669b62
2 changed files with 98 additions and 49 deletions

View file

@ -44,6 +44,10 @@ class PaynymDetailsPopup extends ConsumerStatefulWidget {
class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> { class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
bool _showInsufficientFundsInfo = false; bool _showInsufficientFundsInfo = false;
Future<void> _onSend() async {
// todo send
}
Future<void> _onConnectPressed() async { Future<void> _onConnectPressed() async {
bool canPop = false; bool canPop = false;
unawaited( unawaited(
@ -63,7 +67,7 @@ class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
.getManager(widget.walletId) .getManager(widget.walletId)
.wallet as DogecoinWallet; .wallet as DogecoinWallet;
if (wallet.hasConnected(widget.accountLite.code)) { if (await wallet.hasConnected(widget.accountLite.code)) {
canPop = true; canPop = true;
Navigator.of(context).pop(); Navigator.of(context).pop();
// TODO show info popup // TODO show info popup
@ -136,6 +140,9 @@ class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final wallet = ref.watch(walletsChangeNotifierProvider.select(
(value) => value.getManager(widget.walletId).wallet as DogecoinWallet));
return DesktopDialog( return DesktopDialog(
maxWidth: MediaQuery.of(context).size.width - 32, maxWidth: MediaQuery.of(context).size.width - 32,
maxHeight: double.infinity, maxHeight: double.infinity,
@ -168,20 +175,49 @@ class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
), ),
], ],
), ),
PrimaryButton( FutureBuilder(
label: "Connect", future: wallet.hasConnected(widget.accountLite.code),
buttonHeight: ButtonHeight.l, builder: (context, AsyncSnapshot<bool> snapshot) {
icon: SvgPicture.asset( if (snapshot.connectionState == ConnectionState.done &&
Assets.svg.circlePlusFilled, snapshot.hasData) {
width: 10, if (snapshot.data!) {
height: 10, return PrimaryButton(
color: Theme.of(context) label: "Send",
.extension<StackColors>()! buttonHeight: ButtonHeight.s,
.buttonTextPrimary, icon: SvgPicture.asset(
), Assets.svg.circleArrowUpRight,
iconSpacing: 4, width: 16,
width: 86, height: 16,
onPressed: _onConnectPressed, color: Theme.of(context)
.extension<StackColors>()!
.buttonTextPrimary,
),
iconSpacing: 6,
onPressed: _onSend,
);
} else {
return PrimaryButton(
label: "Connect",
buttonHeight: ButtonHeight.s,
icon: SvgPicture.asset(
Assets.svg.circlePlusFilled,
width: 16,
height: 16,
color: Theme.of(context)
.extension<StackColors>()!
.buttonTextPrimary,
),
iconSpacing: 6,
onPressed: _onConnectPressed,
);
}
} else {
return const SizedBox(
height: 100,
child: LoadingIndicator(),
);
}
},
), ),
], ],
), ),

View file

@ -63,7 +63,7 @@ class _PaynymDetailsPopupState extends ConsumerState<DesktopPaynymDetails> {
.getManager(widget.walletId) .getManager(widget.walletId)
.wallet as DogecoinWallet; .wallet as DogecoinWallet;
if (wallet.hasConnected(widget.accountLite.code)) { if (await wallet.hasConnected(widget.accountLite.code)) {
canPop = true; canPop = true;
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
// TODO show info popup // TODO show info popup
@ -187,40 +187,53 @@ class _PaynymDetailsPopupState extends ConsumerState<DesktopPaynymDetails> {
), ),
Row( Row(
children: [ children: [
if (!wallet.hasConnected(widget.accountLite.code)) Expanded(
Expanded( child: FutureBuilder(
child: PrimaryButton( future: wallet.hasConnected(widget.accountLite.code),
label: "Connect", builder: (context, AsyncSnapshot<bool> snapshot) {
buttonHeight: ButtonHeight.s, if (snapshot.connectionState ==
icon: SvgPicture.asset( ConnectionState.done &&
Assets.svg.circlePlusFilled, snapshot.hasData) {
width: 16, if (snapshot.data!) {
height: 16, return PrimaryButton(
color: Theme.of(context) label: "Send",
.extension<StackColors>()! buttonHeight: ButtonHeight.s,
.buttonTextPrimary, icon: SvgPicture.asset(
), Assets.svg.circleArrowUpRight,
iconSpacing: 6, width: 16,
onPressed: _onConnectPressed, height: 16,
), color: Theme.of(context)
), .extension<StackColors>()!
if (wallet.hasConnected(widget.accountLite.code)) .buttonTextPrimary,
Expanded( ),
child: PrimaryButton( iconSpacing: 6,
label: "Send", onPressed: _onSend,
buttonHeight: ButtonHeight.s, );
icon: SvgPicture.asset( } else {
Assets.svg.circleArrowUpRight, return PrimaryButton(
width: 16, label: "Connect",
height: 16, buttonHeight: ButtonHeight.s,
color: Theme.of(context) icon: SvgPicture.asset(
.extension<StackColors>()! Assets.svg.circlePlusFilled,
.buttonTextPrimary, width: 16,
), height: 16,
iconSpacing: 6, color: Theme.of(context)
onPressed: _onSend, .extension<StackColors>()!
), .buttonTextPrimary,
),
iconSpacing: 6,
onPressed: _onConnectPressed,
);
}
} else {
return const SizedBox(
height: 100,
child: LoadingIndicator(),
);
}
},
), ),
),
const SizedBox( const SizedBox(
width: 20, width: 20,
), ),