forked from argentlabs/argent-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request argentlabs#1971 from argentlabs/feat/zod-token-schema
feat: use zod token schema
- Loading branch information
Showing
3 changed files
with
53 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
export interface BaseToken { | ||
address: string | ||
networkId: string | ||
} | ||
import { z } from "zod" | ||
|
||
export interface RequestToken extends Omit<BaseToken, "networkId"> { | ||
address: string | ||
networkId?: string | ||
name?: string | ||
symbol?: string | ||
decimals?: number | ||
} | ||
export const BaseTokenSchema = z.object( | ||
{ | ||
address: z.string({ required_error: "Address is required" }), | ||
networkId: z.string({ required_error: "Network is required" }), | ||
}, | ||
{ required_error: "BaseToken is required" }, | ||
) | ||
|
||
export interface Token extends Required<RequestToken> { | ||
image?: string | ||
showAlways?: boolean | ||
} | ||
export type BaseToken = z.infer<typeof BaseTokenSchema> | ||
|
||
export const RequestTokenSchema = z.object({ | ||
address: z.string(), | ||
networkId: z.string().optional(), | ||
name: z.string().optional(), | ||
symbol: z.string().optional(), | ||
decimals: z.number().optional(), | ||
}) | ||
|
||
export type RequestToken = z.infer<typeof RequestTokenSchema> | ||
|
||
export const TokenSchema = RequestTokenSchema.required().extend({ | ||
image: z.string().optional(), | ||
showAlways: z.boolean().optional(), | ||
}) | ||
|
||
export type Token = z.infer<typeof TokenSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters