paynym claim cancellation hack (should probably not even allow cancel in ui)

This commit is contained in:
julian 2023-01-04 11:37:39 -06:00
parent 33926d2b5e
commit c4e5e9e8b6
2 changed files with 66 additions and 29 deletions

View file

@ -5,6 +5,7 @@ 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/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
@ -49,39 +50,62 @@ class _RestoringDialogState extends State<ClaimingPaynymDialog>
Widget build(BuildContext context) {
if (Util.isDesktop) {
return DesktopDialog(
child: Padding(
maxWidth: 580,
maxHeight: double.infinity,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
DesktopDialogCloseButton(
onPressedOverride: () => Navigator.of(context).pop(true),
),
],
),
RotationTransition(
turns: _spinAnimation,
child: SvgPicture.asset(
Assets.svg.arrowRotate,
color:
Theme.of(context).extension<StackColors>()!.accentColorDark,
width: 40,
height: 40,
),
),
Padding(
padding: const EdgeInsets.all(40),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Claiming PayNym",
style: STextStyles.desktopH3(context),
style: STextStyles.desktopH2(context),
),
const SizedBox(
height: 20,
),
Text(
"We are generating your PayNym",
style: STextStyles.desktopSubtitleH1(context),
style: STextStyles.desktopTextMedium(context).copyWith(
color:
Theme.of(context).extension<StackColors>()!.textDark3,
),
),
const SizedBox(
height: 40,
),
RotationTransition(
turns: _spinAnimation,
child: SvgPicture.asset(
Assets.svg.arrowRotate,
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark,
width: 24,
height: 24,
),
SecondaryButton(
label: "Cancel",
width: 272,
onPressed: () {
Navigator.of(context).pop(true);
},
),
],
),
),
],
),
);
} else {
return WillPopScope(

View file

@ -165,15 +165,20 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
.getManager(widget.walletId)
.wallet as DogecoinWallet;
if (shouldCancel) return;
// get payment code
final pCode = await wallet.getPaymentCode();
if (shouldCancel) return;
// attempt to create new entry in paynym.is db
final created = await ref
.read(paynymAPIProvider)
.create(pCode.toString());
debugPrint("created:$created");
if (shouldCancel) return;
if (created.value!.claimed) {
// payment code already claimed
@ -193,18 +198,26 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
return;
}
if (shouldCancel) return;
final token =
await ref.read(paynymAPIProvider).token(pCode.toString());
if (shouldCancel) return;
// sign token with notification private key
final signature =
await wallet.signStringWithNotificationKey(token.value!);
if (shouldCancel) return;
// claim paynym account
final claim = await ref
.read(paynymAPIProvider)
.claim(token.value!, signature);
if (shouldCancel) return;
if (claim.value?.claimed == pCode.toString()) {
final account =
await ref.read(paynymAPIProvider).nym(pCode.toString());