Skip to content

Commit

Permalink
Merge pull request #662 from invariant-labs/display-timeout-error-in-…
Browse files Browse the repository at this point in the history
…snackbar

add timeout error message to snackbars
  • Loading branch information
p6te authored Jun 26, 2024
2 parents bdbe059 + 9c4903e commit 801baf0
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 67 deletions.
2 changes: 2 additions & 0 deletions src/store/consts/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,5 @@ export const STABLECOIN_ADDRESSES: string[] = [
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
] // USDC, USDT

export const TIMEOUT_ERROR_MESSAGE = 'Transaction timed out. Check the details to see if it passed.'
178 changes: 128 additions & 50 deletions src/store/sagas/positions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SIGNING_SNACKBAR_CONFIG, WRAPPED_SOL_ADDRESS } from '@consts/static'
import { SIGNING_SNACKBAR_CONFIG, TIMEOUT_ERROR_MESSAGE, WRAPPED_SOL_ADDRESS } from '@consts/static'
import {
createLiquidityPlot,
createLoaderKey,
Expand Down Expand Up @@ -30,6 +30,7 @@ import {
PublicKey,
SystemProgram,
Transaction,
TransactionExpiredTimeoutError,
sendAndConfirmRawTransaction
} from '@solana/web3.js'
import { getMarketProgram } from '@web3/programs/amm'
Expand Down Expand Up @@ -310,13 +311,24 @@ function* handleInitPositionAndPoolWithSOL(action: PayloadAction<InitPositionDat
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down Expand Up @@ -508,13 +520,24 @@ function* handleInitPositionWithSOL(action: PayloadAction<InitPositionData>): Ge
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down Expand Up @@ -669,13 +692,24 @@ export function* handleInitPosition(action: PayloadAction<InitPositionData>): Ge
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down Expand Up @@ -918,13 +952,24 @@ export function* handleClaimFeeWithSOL(positionIndex: number) {
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to claim fee. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down Expand Up @@ -1043,13 +1088,24 @@ export function* handleClaimFee(action: PayloadAction<number>) {
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to claim fee. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down Expand Up @@ -1215,13 +1271,24 @@ export function* handleClosePositionWithSOL(data: ClosePositionData) {
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to close position. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down Expand Up @@ -1370,13 +1437,24 @@ export function* handleClosePosition(action: PayloadAction<ClosePositionData>) {
closeSnackbar(loaderSigningTx)
yield put(snackbarsActions.remove(loaderSigningTx))

yield put(
snackbarsActions.add({
message: 'Failed to close position. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}
}
}

Expand Down
63 changes: 46 additions & 17 deletions src/store/sagas/swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SIGNING_SNACKBAR_CONFIG, WRAPPED_SOL_ADDRESS } from '@consts/static'
import { SIGNING_SNACKBAR_CONFIG, TIMEOUT_ERROR_MESSAGE, WRAPPED_SOL_ADDRESS } from '@consts/static'
import { createLoaderKey, solToPriorityFee } from '@consts/utils'
import { Pair } from '@invariant-labs/sdk'
import { actions as snackbarsActions } from '@reducers/snackbars'
Expand All @@ -8,7 +8,13 @@ import { network, rpcAddress } from '@selectors/solanaConnection'
import { accounts } from '@selectors/solanaWallet'
import { swap } from '@selectors/swap'
import { NATIVE_MINT, TOKEN_PROGRAM_ID, Token } from '@solana/spl-token'
import { Keypair, SystemProgram, Transaction, sendAndConfirmRawTransaction } from '@solana/web3.js'
import {
Keypair,
SystemProgram,
Transaction,
TransactionExpiredTimeoutError,
sendAndConfirmRawTransaction
} from '@solana/web3.js'
import { getMarketProgram } from '@web3/programs/amm'
import { call, put, select, takeEvery } from 'typed-redux-saga'
import { getConnection } from './connection'
Expand Down Expand Up @@ -281,14 +287,26 @@ export function* handleSwapWithSOL(): Generator {

yield put(swapActions.setSwapSuccess(false))

yield put(
snackbarsActions.add({
message:
'Failed to send. Please unwrap wrapped SOL in your wallet if you have any and try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message:
'Failed to send. Please unwrap wrapped SOL in your wallet if you have any and try again.',
variant: 'error',
persist: false
})
)
}

closeSnackbar(loaderSwappingTokens)
yield put(snackbarsActions.remove(loaderSwappingTokens))
closeSnackbar(loaderSigningTx)
Expand Down Expand Up @@ -428,13 +446,24 @@ export function* handleSwap(): Generator {

yield put(swapActions.setSwapSuccess(false))

yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
if (error instanceof TransactionExpiredTimeoutError) {
yield put(
snackbarsActions.add({
message: TIMEOUT_ERROR_MESSAGE,
variant: 'error',
persist: true,
txid: error.signature
})
)
} else {
yield put(
snackbarsActions.add({
message: 'Failed to send. Please try again.',
variant: 'error',
persist: false
})
)
}

closeSnackbar(loaderSwappingTokens)
yield put(snackbarsActions.remove(loaderSwappingTokens))
Expand Down

0 comments on commit 801baf0

Please sign in to comment.