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

View file

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