pull down to refresh paynym home view on mobile

This commit is contained in:
julian 2023-02-02 14:34:35 -06:00
parent 4fbf38fd11
commit 1d4812c5b2
2 changed files with 192 additions and 108 deletions

View file

@ -3,11 +3,17 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/paynym/subwidgets/paynym_card_button.dart';
import 'package:stackwallet/providers/global/paynym_api_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
class PaynymFollowersList extends ConsumerStatefulWidget {
@ -54,7 +60,42 @@ class _PaynymFollowersListState extends ConsumerState<PaynymFollowersList> {
ref.watch(myPaynymAccountStateProvider.state).state?.followers;
final count = followers?.length ?? 0;
return ListView.separated(
return ConditionalParent(
condition: !isDesktop,
builder: (child) => RefreshIndicator(
child: child,
onRefresh: () async {
try {
final manager = ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId);
// get wallet to access paynym calls
final wallet = manager.wallet as PaynymWalletInterface;
// get payment code
final pCode = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin),
);
// get account from api
final account =
await ref.read(paynymAPIProvider).nym(pCode.toString());
// update my account
if (account.value != null) {
ref.read(myPaynymAccountStateProvider.state).state =
account.value!;
}
} catch (e) {
Logging.instance.log(
"Failed pull down refresh of paynym home page: $e",
level: LogLevel.Warning,
);
}
},
),
child: ListView.separated(
itemCount: max(count, 1),
separatorBuilder: (BuildContext context, int index) => Container(
height: 1.5,
@ -109,6 +150,7 @@ class _PaynymFollowersListState extends ConsumerState<PaynymFollowersList> {
);
}
},
),
);
}
}

View file

@ -3,11 +3,17 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/paynym/subwidgets/paynym_card_button.dart';
import 'package:stackwallet/providers/global/paynym_api_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
class PaynymFollowingList extends ConsumerStatefulWidget {
@ -54,7 +60,42 @@ class _PaynymFollowingListState extends ConsumerState<PaynymFollowingList> {
ref.watch(myPaynymAccountStateProvider.state).state?.following;
final count = following?.length ?? 0;
return ListView.separated(
return ConditionalParent(
condition: !isDesktop,
builder: (child) => RefreshIndicator(
child: child,
onRefresh: () async {
try {
final manager = ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId);
// get wallet to access paynym calls
final wallet = manager.wallet as PaynymWalletInterface;
// get payment code
final pCode = await wallet.getPaymentCode(
DerivePathTypeExt.primaryFor(manager.coin),
);
// get account from api
final account =
await ref.read(paynymAPIProvider).nym(pCode.toString());
// update my account
if (account.value != null) {
ref.read(myPaynymAccountStateProvider.state).state =
account.value!;
}
} catch (e) {
Logging.instance.log(
"Failed pull down refresh of paynym home page: $e",
level: LogLevel.Warning,
);
}
},
),
child: ListView.separated(
itemCount: max(count, 1),
separatorBuilder: (BuildContext context, int index) => Container(
height: 1.5,
@ -109,6 +150,7 @@ class _PaynymFollowingListState extends ConsumerState<PaynymFollowingList> {
);
}
},
),
);
}
}