Skip to content

Commit 126583e

Browse files
committed
refactor: add validation for intent api + move to utils
1 parent 4ef2bc6 commit 126583e

File tree

6 files changed

+1039
-32
lines changed

6 files changed

+1039
-32
lines changed

packages/bridge-controller/src/utils/validators.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,37 @@ export const validateQuoteResponse = (
335335
assert(data, QuoteResponseSchema);
336336
return true;
337337
};
338+
339+
export enum IntentOrderStatus {
340+
PENDING = 'pending',
341+
SUBMITTED = 'submitted',
342+
CONFIRMED = 'confirmed',
343+
COMPLETED = 'completed',
344+
FAILED = 'failed',
345+
CANCELLED = 'cancelled',
346+
EXPIRED = 'expired',
347+
}
348+
349+
export type IntentOrder = {
350+
id: string;
351+
status: IntentOrderStatus;
352+
txHash?: string;
353+
metadata: {
354+
txHashes?: string[] | string;
355+
};
356+
};
357+
358+
export const IntentOrderResponseSchema = type({
359+
id: string(),
360+
status: enums(Object.values(IntentOrderStatus)),
361+
txHash: optional(string()),
362+
metadata: type({
363+
txHashes: optional(union([array(string()), string()])),
364+
}),
365+
});
366+
367+
export const validateIntentOrderResponse = (
368+
data: unknown,
369+
): data is Infer<typeof IntentOrderResponseSchema> => {
370+
return is(data, IntentOrderResponseSchema);
371+
};

0 commit comments

Comments
 (0)