diff --git a/packages/daimo-common/src/daimoPay.ts b/packages/daimo-common/src/daimoPay.ts index 189bb82ca..1bc3776b7 100644 --- a/packages/daimo-common/src/daimoPay.ts +++ b/packages/daimo-common/src/daimoPay.ts @@ -1,9 +1,16 @@ import { ForeignToken } from "@daimo/contract"; import { base58 } from "@scure/base"; -import { Address, bytesToBigInt, Hex, numberToBytes, zeroAddress } from "viem"; +import { + Address, + bytesToBigInt, + getAddress, + Hex, + numberToBytes, + zeroAddress, +} from "viem"; import z from "zod"; -import { BigIntStr } from "./model"; +import { BigIntStr, zAddress } from "./model"; // lifecycle: waiting payment -> processed. export enum DaimoPayOrderStatusSource { @@ -36,6 +43,34 @@ export interface DaimoPayOrderItem { image: string; } +// NOTE: be careful to modify this type only in backward-compatible ways. +// Add OPTIONAL fields, etc. Anything else requires a migration. +export const zDaimoPayOrderMetadata = z.object({ + items: z.array( + z.object({ + name: z.string(), + description: z.string(), + image: z.string(), + }), + ), + paymentOptions: z.array(z.string()), + payer: z + .object({ + preferredChains: z.array(z.number()).optional(), + preferrredTokens: z + .array( + z.object({ + chain: z.number(), + address: zAddress.transform((a) => getAddress(a)), + }), + ) + .optional(), + }) + .optional(), +}); + +export type DaimoPayOrderMetadata = z.infer; + export type DaimoPayDehydratedOrder = { mode: DaimoPayOrderMode.SALE | DaimoPayOrderMode.CHOOSE_AMOUNT; id: bigint; @@ -43,11 +78,10 @@ export type DaimoPayDehydratedOrder = { destFinalCall: OnChainCall; destNonce: bigint; intent: string; - itemsJson: string | null; - paymentOptionsJson: string; redirectUri: string | null; orgId: string | null; createdAt: number | null; + metadata: DaimoPayOrderMetadata; }; export type DaimoPayHydratedOrder = {