Skip to content

Commit

Permalink
Merge branch 'swap-endpoint' into support-transfer-with-auth-swap
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 committed Jan 3, 2025
2 parents a8ef891 + 463573b commit 61f7949
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions api/relay/_strategies/gelato.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export function getGelatoStrategy(): RelayStrategy {
taskStatus.taskState
)
) {
throw new Error(
`Can not relay request via Gelato due to task state ${taskStatus.taskState}`
);
throw new GelatoTaskStatusError(taskStatus);
}

if (taskStatus.transactionHash) {
Expand Down Expand Up @@ -73,20 +71,50 @@ async function relayWithGelatoApi({
return response.data.taskId as string;
}

type TaskStatus = {
taskState:
| "CheckPending"
| "ExecPending"
| "ExecSuccess"
| "ExecReverted"
| "WaitingForConfirmation"
| "Blacklisted"
| "Cancelled"
| "NotFound";
chainId: number;
taskId: string;
creationDate: string;
lastCheckDate?: string;
lastCheckMessage?: string;
transactionHash?: string;
blockNumber?: number;
executionDate?: string;
gasUsed?: string;
effectiveGasPrice?: string;
};

async function getGelatoTaskStatus(taskId: string) {
const response = await axios.get<{
task: {
taskState:
| "CheckPending"
| "ExecPending"
| "ExecSuccess"
| "ExecReverted"
| "WaitingForConfirmation"
| "Blacklisted"
| "Cancelled"
| "NotFound";
transactionHash?: string;
};
}>(`${gelatoBaseUrl}/tasks/status/${taskId}`);
const response = await axios.get<{ task: TaskStatus }>(
`${gelatoBaseUrl}/tasks/status/${taskId}`
);
return response.data.task;
}

class GelatoTaskStatusError extends Error {
taskStatus: TaskStatus;

constructor(taskStatus: TaskStatus) {
super(
`Can not relay request via Gelato due to task state ${taskStatus.taskState}`
);
this.taskStatus = taskStatus;
}

toJSON() {
return {
name: this.name,
message: this.message,
taskStatus: this.taskStatus,
};
}
}

0 comments on commit 61f7949

Please sign in to comment.