Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: DaimoPayOrderMetadata #1349

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 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 @@ -33,21 +40,48 @@ export type DaimoPayOrderUpdate =
export interface DaimoPayOrderItem {
name: string;
description: string;
image: string;
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({
intent: z.string(),
items: z.array(
z.object({
name: z.string(),
description: z.string(),
image: z.string().optional(),
}),
),
paymentOptions: z.array(z.string()),
payer: z
.object({
preferredChains: z.array(z.number()).optional(),
preferredTokens: 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 All @@ -67,12 +101,10 @@ export type DaimoPayHydratedOrder = {
destStatus: DaimoPayOrderStatusDest;
destFastFinishTxHash: Hex | null;
destClaimTxHash: Hex | null;
intent: string;
itemsJson: string | null;
paymentOptionsJson: string;
redirectUri: string | null;
orgId: string | null;
createdAt: number | null;
metadata: DaimoPayOrderMetadata;
};

export type DaimoPayHydratedOrderWithoutHandoffAddr = Omit<
Expand Down
Loading