@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
43 lines (42 loc) • 2.03 kB
TypeScript
/**
* clientMetadata is a type for FE to store historical state of a checkoutItem
* It should be mostly derived by backend data but currently we don't have capacity to do it.
*
* Make sure it is SERIALIZABLE and BACKWARD COMPATIBLE!!
*/
import type { ApiCheckoutClientMetadata } from '@funkit/utils';
import type { FunkitActiveCheckoutItem, FunkitCheckoutActionParams, FunkitCheckoutConfig } from '~/providers/FunkitCheckoutContext';
import type { FunkitCheckoutQuoteResult } from './quote';
type Serialize<T> = T extends (...args: never[]) => unknown ? DeepSerialize<ReturnType<T>> : T extends object ? DeepSerialize<T> : T;
type DeepSerialize<T> = {
[K in keyof T]: Serialize<T[K]>;
};
/**
* Historical Checkout Configuration stored in the server
* This is similar to FunkitCheckoutConfig but with some fields changed to serializable types
* */
export type ServerCheckoutConfig = DeepSerialize<FunkitCheckoutConfig>;
type HistoricalCheckoutItemKey = 'id' | 'startTimestampMs' | 'finalDollarValue' | 'latestQuote' | 'depositAddress' | 'selectedSourceAssetInfo' | 'selectedPaymentMethodInfo';
/**
* HistoricalCheckoutItem stored in the server
*
* Make sure it is SERIALIZABLE and BACKWARD COMPATIBLE!!
**/
export interface HistoricalCheckoutItem extends Pick<FunkitActiveCheckoutItem, HistoricalCheckoutItemKey> {
initSettings: {
config: ServerCheckoutConfig;
};
isWithdrawal?: boolean;
}
/**
* Sanitizes checkoutItem to generate a clientMetadata object to be saved in backend.
* Ensures that no react components get sent to backend and the object isn't too big as well.
*/
export declare function generateClientMetadataForBackend({ checkoutItem, latestQuote, actionsParams, isWithdrawal, }: {
checkoutItem: FunkitActiveCheckoutItem;
latestQuote: FunkitCheckoutQuoteResult;
actionsParams?: FunkitCheckoutActionParams[];
isWithdrawal?: boolean;
}): ApiCheckoutClientMetadata;
export declare function generateClientMetadataForTokenTransfer(): HistoricalCheckoutItem;
export {};