@emurgo/bringweb3-chrome-extension-kit
Version:
Crypto cashback integration kit for crypto outlets extension
97 lines (92 loc) • 4.12 kB
text/typescript
interface Configuration$1 {
getWalletAddress: () => Promise<WalletAddress>;
walletAddressUpdateCallback?: (callback: () => void) => void;
walletAddressListeners?: string[];
promptLogin: () => Promise<void>;
lightTheme?: Style;
darkTheme?: Style;
theme: string;
text: 'upper' | 'lower';
switchWallet: boolean;
}
/**
* Initializes the content script for the Bring extension.
*
* @async
* @function bringInitContentScript
* @param {Object} configuration - The configuration object.
* @param {Function} configuration.getWalletAddress - A function that returns a Promise resolving to the wallet address.
* @param {Function} configuration.promptLogin - A function to prompt the user to login.
* @param {string[]} configuration.walletAddressListeners - An optional array of strings representing wallet address listeners.
* @param {Function} [configuration.walletAddressUpdateCallback] - An optional callback function for wallet address updates.
* @param {Object} [configuration.lightTheme] - Optional light theme settings.
* @param {Object} [configuration.darkTheme] - Optional dark theme settings.
* @param {string} configuration.theme - The chosen theme, light | dark.
* @param {string} configuration.text - The chosen case for some of the texts, upper | lower.
* @throws {Error} Throws an error if any required configuration is missing.
* @returns {Promise<void>}
*
* @description
* This function sets up event listeners for wallet address changes, iframe messages,
* and Chrome runtime messages. It handles actions such as getting the wallet address
* and injecting iframes based on received messages.
*
* @example
* bringInitContentScript({
* getWalletAddress: async () => '0x1234...',
* promptLogin: () => { ... },
* walletAddressListeners: ["listener1", "listener2"],
* theme: 'light',
* text: 'lower',
* lightTheme: { ... },
* darkTheme: { ... }
* });
*/
declare const bringInitContentScript: ({ getWalletAddress, promptLogin, walletAddressListeners, walletAddressUpdateCallback, lightTheme, darkTheme, theme, text, switchWallet }: Configuration$1) => Promise<void>;
interface Configuration {
identifier: string;
apiEndpoint: string;
whitelistEndpoint?: string;
cashbackPagePath?: string;
isEnabledByDefault: boolean;
showNotifications?: boolean;
notificationCallback?: () => void;
}
declare const bringInitBackground: ({ identifier, apiEndpoint, cashbackPagePath, whitelistEndpoint, isEnabledByDefault, showNotifications, notificationCallback }: Configuration) => Promise<void>;
interface TurnOff {
isTurnedOff: boolean;
}
/**
* Retrieves the current "turn off" status, true means turned off and false is turned on
*
* @returns A Promise resolving to the turn-off state
* @throws Will reject if there's an error communicating with the background script
*/
declare const getTurnOff: () => Promise<TurnOff>;
/**
* Sets the opt-out status for the extension
*
* @param state - Boolean indicating whether to turn off (true) or turn on (false)
* @returns A Promise resolving to the new turn-off state
* @throws Will reject if there's an error communicating with the background script
*/
declare const setTurnOff: (state: boolean) => Promise<TurnOff>;
interface PopupEnabled {
isPopupEnabled: boolean;
}
/**
* Retrieves the current "turn off" status, true means turned off and false is turned on
*
* @returns A Promise resolving to the turn-off state
* @throws Will reject if there's an error communicating with the background script
*/
declare const getPopupEnabled: () => Promise<PopupEnabled>;
/**
* Sets if popup feature is enabled or disabled
*
* @param state - Boolean indicating whether popup feature is enabled (true) or disabled (false)
* @returns A Promise resolving to the new turn-off state
* @throws Will reject if there's an error communicating with the background script
*/
declare const setPopupEnabled: (state: boolean) => Promise<PopupEnabled>;
export { bringInitBackground, bringInitContentScript, getPopupEnabled, getTurnOff, setPopupEnabled, setTurnOff };