From d95aa99c994bc601715da37f549d05fbae84f2bd Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Thu, 8 May 2025 19:00:45 -0700 Subject: [PATCH 1/4] Handle TokenAccountNotFoundError in recoverPurchaseIfNecessary --- packages/common/src/store/buy-usdc/sagas.ts | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/common/src/store/buy-usdc/sagas.ts b/packages/common/src/store/buy-usdc/sagas.ts index 1e3d5393e0b..6fe484e23ea 100644 --- a/packages/common/src/store/buy-usdc/sagas.ts +++ b/packages/common/src/store/buy-usdc/sagas.ts @@ -1,8 +1,10 @@ import { USDC } from '@audius/fixed-decimal' import { + Account, createTransferCheckedInstruction, getAccount, - getAssociatedTokenAddressSync + getAssociatedTokenAddressSync, + TokenAccountNotFoundError } from '@solana/spl-token' import { Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js' import retry from 'async-retry' @@ -384,11 +386,20 @@ function* recoverPurchaseIfNecessary() { mint: 'USDC' } ) - const accountInfo = yield* call( - getAccount, - sdk.services.solanaClient.connection, - usdcTokenAccount - ) + + let accountInfo: Account | null = null + try { + accountInfo = yield* call( + getAccount, + sdk.services.solanaClient.connection, + usdcTokenAccount + ) + } catch (e) { + if (e instanceof TokenAccountNotFoundError) { + return + } + throw e + } const amount = accountInfo?.amount ?? BigInt(0) if (amount === BigInt(0)) { return From 829a4279552872fba46db3f9f35f21b320d73691 Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Thu, 8 May 2025 19:04:17 -0700 Subject: [PATCH 2/4] simplify --- packages/common/src/store/buy-usdc/sagas.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/common/src/store/buy-usdc/sagas.ts b/packages/common/src/store/buy-usdc/sagas.ts index 6fe484e23ea..d719f461434 100644 --- a/packages/common/src/store/buy-usdc/sagas.ts +++ b/packages/common/src/store/buy-usdc/sagas.ts @@ -387,19 +387,11 @@ function* recoverPurchaseIfNecessary() { } ) - let accountInfo: Account | null = null - try { - accountInfo = yield* call( - getAccount, - sdk.services.solanaClient.connection, - usdcTokenAccount - ) - } catch (e) { - if (e instanceof TokenAccountNotFoundError) { - return - } - throw e - } + const accountInfo = yield* call( + getAccount, + sdk.services.solanaClient.connection, + usdcTokenAccount + ) const amount = accountInfo?.amount ?? BigInt(0) if (amount === BigInt(0)) { return @@ -466,6 +458,9 @@ function* recoverPurchaseIfNecessary() { }) ) } catch (e) { + if (e instanceof TokenAccountNotFoundError) { + return + } yield* put(recoveryStatusChanged({ status: Status.ERROR })) yield* call(reportToSentry, { level: ErrorLevel.Error, From 59f847a4be52fb2c6fdbbdaad2da1526df804375 Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Thu, 8 May 2025 19:04:56 -0700 Subject: [PATCH 3/4] drop line --- packages/common/src/store/buy-usdc/sagas.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/common/src/store/buy-usdc/sagas.ts b/packages/common/src/store/buy-usdc/sagas.ts index d719f461434..93dd716a37a 100644 --- a/packages/common/src/store/buy-usdc/sagas.ts +++ b/packages/common/src/store/buy-usdc/sagas.ts @@ -386,7 +386,6 @@ function* recoverPurchaseIfNecessary() { mint: 'USDC' } ) - const accountInfo = yield* call( getAccount, sdk.services.solanaClient.connection, From 1934b3386775b9ee1fae5eaac6360bcc24faeedb Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Thu, 8 May 2025 19:13:07 -0700 Subject: [PATCH 4/4] improve ordering --- packages/common/src/store/buy-usdc/sagas.ts | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/common/src/store/buy-usdc/sagas.ts b/packages/common/src/store/buy-usdc/sagas.ts index 93dd716a37a..d5f419eed1b 100644 --- a/packages/common/src/store/buy-usdc/sagas.ts +++ b/packages/common/src/store/buy-usdc/sagas.ts @@ -1,6 +1,5 @@ import { USDC } from '@audius/fixed-decimal' import { - Account, createTransferCheckedInstruction, getAccount, getAssociatedTokenAddressSync, @@ -386,12 +385,22 @@ function* recoverPurchaseIfNecessary() { mint: 'USDC' } ) - const accountInfo = yield* call( - getAccount, - sdk.services.solanaClient.connection, - usdcTokenAccount - ) - const amount = accountInfo?.amount ?? BigInt(0) + + let amount: bigint + try { + const accountInfo = yield* call( + getAccount, + sdk.services.solanaClient.connection, + usdcTokenAccount + ) + amount = accountInfo.amount + } catch (e) { + if (e instanceof TokenAccountNotFoundError) { + amount = BigInt(0) + } + throw e + } + if (amount === BigInt(0)) { return } @@ -457,9 +466,6 @@ function* recoverPurchaseIfNecessary() { }) ) } catch (e) { - if (e instanceof TokenAccountNotFoundError) { - return - } yield* put(recoveryStatusChanged({ status: Status.ERROR })) yield* call(reportToSentry, { level: ErrorLevel.Error,