Skip to content

Commit

Permalink
fix: gelato error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Mar 9, 2023
1 parent 8725e83 commit aaaaf49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
15 changes: 13 additions & 2 deletions src/hooks/useLastTxLocalStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ export const useLastTxLocalStatus = <T extends BaseTx>({
const txSuccess = tx && tx.status === 1;
const txChainId = tx && tx.chainId;
const txWalletType = tx && tx.walletType;
const isError =
tx &&
!tx.pending &&
((tx && (tx.status === 2 || tx.status === 0)) || !!error);

useEffect(() => {
if (txPending || !!error) {
if (txPending || isError) {
setIsTxStart(true);
}
}, [txPending, error]);
}, [txPending, isError]);

useEffect(() => {
if (tx?.errorMessage) {
setError(tx.errorMessage);
}
}, [tx?.errorMessage]);

async function executeTxWithLocalStatuses({
errorMessage,
Expand Down Expand Up @@ -66,6 +76,7 @@ export const useLastTxLocalStatus = <T extends BaseTx>({
txSuccess,
txChainId,
txWalletType,
isError,
executeTxWithLocalStatuses,
};
};
30 changes: 16 additions & 14 deletions src/web3/store/transactionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,30 @@ type GelatoTaskStatusResponse = {
executionDate?: string;
transactionHash?: string;
blockNumber?: number;
lastCheckMessage?: string;
};
};

export type EthBaseTx = {
type BasicTx = {
chainId: number;
type: string;
from: string;
payload?: object;
localTimestamp: number;
timestamp?: number;
errorMessage?: string;
};

export type EthBaseTx = BasicTx & {
hash: string;
from: string;
to: string;
nonce: number;
chainId: number;
timestamp?: number;
localTimestamp: number;
};

export type GelatoBaseTx = {
from: string;
export type GelatoBaseTx = BasicTx & {
taskId: string;
type: string;
chainId: number;
timestamp?: number;
payload?: object;
hash?: string;
gelatoStatus?: GelatoTXState;
localTimestamp: number;
};

type GelatoTx = {
Expand Down Expand Up @@ -362,13 +361,16 @@ export function createTransactionsSlice<T extends BaseTx>({
tx.gelatoStatus = statusResponse.task.taskState;
tx.pending = selectIsGelatoTXPending(statusResponse.task.taskState);
tx.hash = statusResponse.task.transactionHash;
tx.status = statusResponse.task.taskState == 'ExecSuccess' ? 1 : 0;
tx.status = statusResponse.task.taskState == 'ExecSuccess' ? 1 : 2;
if (statusResponse.task.executionDate) {
const timestamp = new Date(
statusResponse.task.executionDate
).getTime();
tx.timestamp = timestamp;
}
if (statusResponse.task.lastCheckMessage) {
tx.errorMessage = statusResponse.task.lastCheckMessage;
}
})
);
setLocalStorageTxPool(get().transactionsPool);
Expand All @@ -379,7 +381,7 @@ export function createTransactionsSlice<T extends BaseTx>({
`https://relay.gelato.digital/tasks/status/${taskId}/`
);
if (!response.ok) {
//TODO: handle error somehow status 0 error, 1 success
// TODO: handle error somehow
// throw new Error('Gelato API error')
} else {
const gelatoStatus =
Expand Down

0 comments on commit aaaaf49

Please sign in to comment.