@uphold/topper-web-sdk
Version:
Seamless integration of Topper on Web applications
102 lines (87 loc) • 2.76 kB
text/typescript
declare enum Environments {
PRODUCTION = "production",
SANDBOX = "sandbox"
}
declare enum Events {
ALL = "*",
ORDER_CONTINUE_BUTTON_CLICKED = "orderContinueButtonClicked",
ORDER_PLACED = "orderPlaced",
ORDER_WALLET_SEND_BUTTON_CLICKED = "orderWalletSendButtonClicked",
WIDGET_CONTINUE_BUTTON_CLICKED = "widgetContinueButtonClicked"
}
declare enum Flows {
CRYPTO_OFFRAMP = "crypto_offramp",
CRYPTO_ONRAMP = "crypto_onramp"
}
declare enum InitialScreens {
AUTHENTICATION = "authentication"
}
declare enum Locales {
EN = "en",
EN_US = "en-US",
PT = "pt",
PT_BR = "pt-BR",
ES = "es",
ES_ES = "es-ES"
}
declare enum Themes {
DARK = "dark",
LIGHT = "light"
}
declare enum Handlers {
SIGN_AND_BROADCAST_TRANSACTION = "signAndBroadcastTransaction"
}
declare enum Urls {
PRODUCTION = "https://app.topperpay.com",
SANDBOX = "https://app.sandbox.topperpay.com",
WEBSITE = "https://www.topperpay.com/"
}
declare enum Variants {
IFRAME = "iframe",
NEW_TAB = "new-tab",
SAME_TAB = "same-tab"
}
interface Config {
active_flow?: Flows | null;
environment?: Environments;
initial_screen?: InitialScreens | null;
is_android_app?: boolean;
is_android_webview?: boolean;
is_ios_app?: boolean;
is_ios_webview?: boolean;
locale?: Locales;
theme?: Themes;
variant?: Variants;
}
interface EventPayload {
name?: string;
data: any;
}
type EventHandler = (event: EventPayload) => void;
type Handler<T = any, R = any> = (data?: T) => Promise<R> | R;
declare class TopperWebSdk {
private eventHandlers;
private handlers;
private handleMessage;
private isInitialized;
private targetWindow;
config: Config;
constructor(config?: Config);
static getMainWindow(): any;
static handle<T = any>(handlerName: Handlers, data?: any): Promise<T>;
static triggerEvent(eventName: Events, data?: any): void;
private triggerEvent;
private setConfig;
private initializeMessageListener;
dispose(): void;
initialize({ bootstrapToken, bootstrapTokens, config, iframeElement }: {
bootstrapToken?: string;
bootstrapTokens?: string[];
iframeElement?: HTMLIFrameElement;
config?: Config;
}): void;
on(eventName: Events, handler: EventHandler): void;
registerHandler(handlerName: Handlers, handler: Handler): void;
resolveHandler(handlerName: Handlers, data?: any): Promise<void>;
}
export { Environments as TOPPER_ENVIRONMENTS, Events as TOPPER_EVENTS, Handlers as TOPPER_HANDLERS, InitialScreens as TOPPER_INITIAL_SCREENS, Locales as TOPPER_LOCALES, Themes as TOPPER_THEMES, Urls as TOPPER_URLS, Variants as TOPPER_VARIANTS, TopperWebSdk };