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

pay: clean up typing #1368

Merged
merged 2 commits into from
Nov 6, 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
35 changes: 13 additions & 22 deletions packages/daimo-common/src/daimoPay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ export interface DaimoPayOrderItem {
image?: string;
}

export const zBridgeTokenOutOption = z.object({
token: zAddress.transform((a) => getAddress(a)),
amount: zBigIntStr.transform((a) => BigInt(a)),
});

export const zBridgeTokenOutOptions = z.array(zBridgeTokenOutOption);
export const zBridgeTokenOutOptions = z.array(
z.object({
token: zAddress,
amount: zBigIntStr.transform((a) => BigInt(a)),
}),
);

export type BridgeTokenOutOption = z.infer<typeof zBridgeTokenOutOption>;
export type BridgeTokenOutOptions = z.infer<typeof zBridgeTokenOutOptions>;

// NOTE: be careful to modify this type only in backward-compatible ways.
// Add OPTIONAL fields, etc. Anything else requires a migration.
Expand Down Expand Up @@ -134,6 +134,11 @@ export type DaimoPayHydratedOrder = {
mode: DaimoPayOrderMode.HYDRATED;
id: bigint;
intentAddr: Address;
/**
* @deprecated included for backcompat with old paykit versions. Remove once
* new paykit version is deployed.
* */
handoffAddr: Address;
bridgeTokenOutOptions: DaimoPayTokenAmount[];
selectedBridgeTokenOutAddr: Address | null;
selectedBridgeTokenOutAmount: bigint | null;
Expand All @@ -159,7 +164,7 @@ export type DaimoPayHydratedOrder = {

export type DaimoPayHydratedOrderWithoutIntentAddr = Omit<
DaimoPayHydratedOrder,
"intentAddr"
"intentAddr" | "handoffAddr"
>;

export type DaimoPayOrder = DaimoPayDehydratedOrder | DaimoPayHydratedOrder;
Expand Down Expand Up @@ -213,20 +218,6 @@ export interface DaimoPayTokenAmount {
usd: number; // amount in dollars
}

export type ContractTokenAmount = {
token: Address;
amount: bigint;
};

export function DPTokenAmountToContractTokenAmount(
tokenAmount: DaimoPayTokenAmount,
): ContractTokenAmount {
return {
token: tokenAmount.token.token,
amount: BigInt(tokenAmount.amount),
};
}

export type OnChainCall = {
to: Address;
data: Hex;
Expand Down
Loading