Skip to content

Commit

Permalink
pay: DaimoPayOrderMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Oct 9, 2024
1 parent 8f72325 commit 4b770e8
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions packages/daimo-common/src/daimoPay.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -36,18 +43,45 @@ 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<typeof zDaimoPayOrderMetadata>;

export type DaimoPayDehydratedOrder = {
mode: DaimoPayOrderMode.SALE | DaimoPayOrderMode.CHOOSE_AMOUNT;
id: bigint;
destFinalCallTokenAmount: DaimoPayTokenAmount;
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 = {
Expand Down

0 comments on commit 4b770e8

Please sign in to comment.