Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout error message to snackbars #662

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/store/consts/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,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
Loading