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) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) {
if (snapshot.data!) {
return PrimaryButton(
label: "Send",
buttonHeight: ButtonHeight.s,
icon: SvgPicture.asset( icon: SvgPicture.asset(
Assets.svg.circlePlusFilled, Assets.svg.circleArrowUpRight,
width: 10, width: 16,
height: 10, height: 16,
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.buttonTextPrimary, .buttonTextPrimary,
), ),
iconSpacing: 4, iconSpacing: 6,
width: 86, 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, 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,26 +187,15 @@ class _PaynymDetailsPopupState extends ConsumerState<DesktopPaynymDetails> {
), ),
Row( Row(
children: [ children: [
if (!wallet.hasConnected(widget.accountLite.code))
Expanded( Expanded(
child: PrimaryButton( child: FutureBuilder(
label: "Connect", future: wallet.hasConnected(widget.accountLite.code),
buttonHeight: ButtonHeight.s, builder: (context, AsyncSnapshot<bool> snapshot) {
icon: SvgPicture.asset( if (snapshot.connectionState ==
Assets.svg.circlePlusFilled, ConnectionState.done &&
width: 16, snapshot.hasData) {
height: 16, if (snapshot.data!) {
color: Theme.of(context) return PrimaryButton(
.extension<StackColors>()!
.buttonTextPrimary,
),
iconSpacing: 6,
onPressed: _onConnectPressed,
),
),
if (wallet.hasConnected(widget.accountLite.code))
Expanded(
child: PrimaryButton(
label: "Send", label: "Send",
buttonHeight: ButtonHeight.s, buttonHeight: ButtonHeight.s,
icon: SvgPicture.asset( icon: SvgPicture.asset(
@ -219,6 +208,30 @@ class _PaynymDetailsPopupState extends ConsumerState<DesktopPaynymDetails> {
), ),
iconSpacing: 6, iconSpacing: 6,
onPressed: _onSend, 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(),
);
}
},
), ),
), ),
const SizedBox( const SizedBox(