@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
48 lines (47 loc) • 2.32 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, ApiSelectedPaymentMethodInfo } from '@funkit/utils';
import type { FunkitActiveCheckoutItem, FunkitCheckoutActionParams, FunkitCheckoutConfig } from '~/providers/FunkitCheckoutContext';
import { type PaymentMethodInfo } from './paymentMethods';
import type { FunkitCheckoutQuoteResult } from './quote';
/**
* Historical Checkout Configuration stored in the server
* This is similar to FunkitCheckoutConfig but with some fields changed to serializable types
* */
export type ServerCheckoutConfig = Omit<FunkitCheckoutConfig, 'generateActionsParams'> & {
generateActionsParams?: string;
};
/**
* HistoricalCheckoutItem stored in the server
*
* Make sure it is SERIALIZABLE and BACKWARD COMPATIBLE!!
**/
export interface HistoricalCheckoutItem {
id: FunkitActiveCheckoutItem['id'];
startTimestampMs: FunkitActiveCheckoutItem['startTimestampMs'];
finalDollarValue: FunkitActiveCheckoutItem['finalDollarValue'];
latestQuote: FunkitActiveCheckoutItem['latestQuote'];
depositAddress: FunkitActiveCheckoutItem['depositAddress'];
initSettings: {
config: ServerCheckoutConfig;
};
selectedSourceAssetInfo: FunkitActiveCheckoutItem['selectedSourceAssetInfo'];
selectedPaymentMethodInfo: FunkitActiveCheckoutItem['selectedPaymentMethodInfo'];
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 declare function toApiSelectedPaymentMethodInfo(paymentMethodInfo: PaymentMethodInfo): ApiSelectedPaymentMethodInfo;