swype-sdk
Version:
Official SDK for integrating Swype payment and credit services
258 lines (245 loc) • 7.71 kB
text/typescript
import { JSX } from 'react';
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as zustand from 'zustand';
interface KycModalProps {
eoaAddress: string;
onClose?: () => void;
onComplete?: () => void;
}
declare function KycModal({ eoaAddress, onClose, onComplete, }: KycModalProps): JSX.Element | null;
interface CreditDelegationRequest {
creditType: "aave-v3" | "euler";
from: string;
creditLimit: number;
userParams?: {
vaults: string[];
};
}
type CardStatus = "initiated" | "pending" | "approved" | "userNotExisting" | "review" | "rejected" | "feePending";
interface UserCard {
cardID: string;
creditProviderAddress: string;
type: "virtual" | "physical";
status: "active" | "inactive" | "pending" | "locked";
last4: string;
creditType: "aave-v3" | "euler";
expirationMonth: string;
expirationYear: string;
}
interface SuppliedAsset {
UsageAsCollateralEnabledOnUser: boolean;
amount: number;
amountUSD: number;
collateralAmountBase: string;
collateralAmountBig: number;
supplyRate: number;
underlyingAsset: string;
}
interface BorrowedAsset {
amount: number;
amountUSD: number;
borrowRate: number;
debtAmountBase: string;
debtAmountBig: number;
underlyingAsset: string;
}
interface CreditMetadata {
availableBorrowsBase: number;
borrowPower: number;
borrowValue: number;
eModeCategory: number;
healthFactor: number;
liquidationThreshold: number;
ltv: number;
netAPY: number;
stableBorrowAPY: number;
stableBorrowedAssets: any[];
suppliedAssets: SuppliedAsset[];
suppliedValue: number;
supplyAPY: number;
totalCollateralBase: number;
totalDebtBase: number;
variableBorrowAPY: number;
variableBorrowedAssets: BorrowedAsset[];
}
interface CreditInformationResponse {
data: {
metadata: CreditMetadata;
availableLimit: number;
amountDelegated: number;
SupportedChainIDs: number[];
} | null;
}
interface SwypeSDKConfig {
apiKey: string;
baseUrl?: string;
apiPath?: string;
eoaAddress: string;
signature: string;
deadline: number;
}
type TransactionType = "spend";
type TransactionStatus = "pending" | "declined" | "reversed" | "completed";
type OnchainDirection = "credit" | "debit";
type OnchainStatus = "pending" | "processing" | "completed" | "failed";
type OnchainPurpose = "authorization" | "increment" | "settlement" | "reversal" | "refund" | "recovery";
interface OnchainTransaction {
transaction_hash: string;
chain_id: string;
amount: number;
direction: OnchainDirection;
status: OnchainStatus;
purpose: OnchainPurpose;
created_at: string;
}
interface Merchant {
name: string;
city: string;
country: string;
category: string;
}
interface Transaction {
id: string;
type: TransactionType;
status: TransactionStatus;
amount: number;
currency: string;
local_amount?: number;
local_currency: string;
merchant: Merchant;
declined_reason?: string;
created_at: string;
authorized_at?: string;
posted_at?: string;
onchain_transactions?: OnchainTransaction[];
}
interface OnchainTransactionDetail {
id: string;
transaction_id: string;
direction: OnchainDirection;
chain_id: string;
from_address: string;
to_address: string;
transaction_hash: string;
amount: number;
amount_raw: string;
fee_raw: string;
token: string;
status: OnchainStatus;
purpose: OnchainPurpose;
error_details?: string;
created_at: string;
completed_at?: string;
}
interface OnchainTransactionDetailsResponse {
data: OnchainTransactionDetail[];
}
declare global {
interface Window {
rain?: {
generateSessionId: (pemKey: string) => Promise<{
secretKey: string;
sessionId: string;
}>;
decryptSecret: (data: string, iv: string, secretKey: string) => Promise<string>;
};
}
}
interface CardDetailsCallbacks {
onToast: (message: {
title: string;
description: string;
icon: string;
}) => void;
signTypedData: (params: any) => Promise<string>;
}
interface ManageCardModalProps {
title: string;
onClose: () => void;
callbacks: CardDetailsCallbacks;
address: string;
chainId: number;
}
declare function ManageCardModal({ title, onClose, callbacks, address, chainId, }: ManageCardModalProps): react_jsx_runtime.JSX.Element;
interface DelegateCardParams {
chainID: number;
creditType: "aave-v3" | "euler";
creditLimit: number;
sendTransactionAsync: (params: {
to: string;
value: bigint;
data: string;
}) => Promise<string>;
signTypedDataAsync: (params: {
domain: {
chainId: number;
};
types: Record<string, Array<{
name: string;
type: string;
}>>;
primaryType: string;
message: Record<string, any>;
}) => Promise<string>;
userParams?: {
vaults: string[];
};
}
/**
* Handles the complete card delegation process, including transaction execution,
* card creation, signing authorization, linking to a credit provider, and verification.
*
* @param params - Configuration required to perform card delegation.
* @returns An object indicating success or failure with a descriptive message.
*/
declare function delegateCard({ chainID, creditLimit, creditType, sendTransactionAsync, signTypedDataAsync, userParams, }: DelegateCardParams): Promise<{
success: boolean;
message: string;
}>;
declare function initializeSwypeSDK(config: SwypeSDKConfig): Promise<void>;
declare const generateAuthSign: (eoaAddress: string, signTypedData: (typedData: any) => Promise<string>) => Promise<{
signature: string;
deadline: number;
}>;
interface KycStoreState {
acceptedTerms: boolean;
acceptedRainTerms: boolean;
isKycModalOpen: boolean;
isSumsubProfileVerified: boolean;
setAcceptedTerms: (accepted: boolean) => void;
setAcceptedRainTerms: (accepted: boolean) => void;
setKycModalOpen: (open: boolean) => void;
setIsSumsubProfileVerified: (verified: boolean) => void;
}
declare const useKycStore: zustand.UseBoundStore<zustand.StoreApi<KycStoreState>>;
interface UseCardDataReturn {
status: CardStatus | null;
userCard: UserCard | null;
isUserCardDelegated: boolean;
isLoading: boolean;
error: string | null;
}
declare const useCardData: () => UseCardDataReturn;
type CreditType = "card" | "aave" | "euler";
interface UseCreditDataReturn {
creditInfo: Record<CreditType, CreditInformationResponse | null>;
isLoading: boolean;
error: string | null;
}
declare const useCreditData: () => UseCreditDataReturn;
interface UseGetTransactionsReturn {
transactions: Transaction[];
isLoading: boolean;
error: string | null;
hasNext: boolean;
loadMore: () => Promise<void>;
refetch: () => Promise<void>;
fetchOnchainDetails: (transactionID: string) => Promise<OnchainTransactionDetailsResponse>;
}
/**
* Hook for managing transactions
* Automatically fetches transactions on mount using SDK internal state
* Provides pagination and onchain details functionality
*/
declare const useGetTransactions: () => UseGetTransactionsReturn;
export { type CardDetailsCallbacks, type CardStatus, type CreditDelegationRequest, KycModal, ManageCardModal, type OnchainTransactionDetail, type Transaction, type UserCard, delegateCard, generateAuthSign, initializeSwypeSDK, useCardData, useCreditData, useGetTransactions, useKycStore };