Skip to content

Commit 2081773

Browse files
committed
fix(paynym): handle claim success check and add null-token guard
1 parent ec0542f commit 2081773

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

lib/pages/paynym/paynym_claim_view.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,38 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
240240
final token =
241241
await ref.read(paynymAPIProvider).token(pCode.toString());
242242

243+
debugPrint("token result: $token");
244+
243245
if (shouldCancel) return;
244246

247+
if (token.value == null) {
248+
debugPrint("token fetch failed: ${token.message}");
249+
if (mounted) {
250+
Navigator.of(context, rootNavigator: isDesktop).pop();
251+
}
252+
return;
253+
}
254+
245255
// sign token with notification private key
246256
final signature =
247257
await wallet.signStringWithNotificationKey(token.value!);
248258

259+
debugPrint("signature: $signature");
260+
249261
if (shouldCancel) return;
250262

251263
// claim paynym account
252264
final claim = await ref
253265
.read(paynymAPIProvider)
254266
.claim(token.value!, signature);
255267

268+
debugPrint("claim result: $claim");
269+
256270
if (shouldCancel) return;
257271

258-
if (claim.value?.claimed == pCode.toString()) {
272+
if (claim.value != null &&
273+
(claim.value!.claimed == pCode.toString() ||
274+
claim.value!.claimed == "true")) {
259275
final account =
260276
await ref.read(paynymAPIProvider).nym(pCode.toString());
261277
// if (!account.value!.segwit) {
@@ -286,6 +302,13 @@ class _PaynymClaimViewState extends ConsumerState<PaynymClaimView> {
286302
);
287303
}
288304
} else if (mounted && !shouldCancel) {
305+
debugPrint(
306+
"claim failed or mismatch: "
307+
"claimed=${claim.value?.claimed}, "
308+
"expected=${pCode.toString()}, "
309+
"statusCode=${claim.statusCode}, "
310+
"message=${claim.message}",
311+
);
289312
Navigator.of(context, rootNavigator: isDesktop).pop();
290313
}
291314
},

0 commit comments

Comments
 (0)