FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

View File

@@ -0,0 +1,2 @@
export declare const checkCrossOriginOpenerPolicy: () => Promise<void>, getCrossOriginOpenerPolicy: () => string;
//# sourceMappingURL=checkCrossOriginOpenerPolicy.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"checkCrossOriginOpenerPolicy.d.ts","sourceRoot":"","sources":["../../src/util/checkCrossOriginOpenerPolicy.ts"],"names":[],"mappings":"AA6DA,eAAO,MAAQ,4BAA4B,uBAAE,0BAA0B,cAAwB,CAAC"}

View File

@@ -0,0 +1,56 @@
const COOP_ERROR_MESSAGE = `Coinbase Wallet SDK requires the Cross-Origin-Opener-Policy header to not be set to 'same-origin'. This is to ensure that the SDK can communicate with the Coinbase Smart Wallet app.
Please see https://www.smartwallet.dev/guides/tips/popup-tips#cross-origin-opener-policy for more information.`;
/**
* Creates a checker for the Cross-Origin-Opener-Policy (COOP).
*
* @returns An object with methods to get and check the Cross-Origin-Opener-Policy.
*
* @method getCrossOriginOpenerPolicy
* Retrieves current Cross-Origin-Opener-Policy.
* @throws Will throw an error if the policy has not been checked yet.
*
* @method checkCrossOriginOpenerPolicy
* Checks the Cross-Origin-Opener-Policy of the current environment.
* If in a non-browser environment, sets the policy to 'non-browser-env'.
* If in a browser environment, fetches the policy from the current origin.
* Logs an error if the policy is 'same-origin'.
*/
const createCoopChecker = () => {
let crossOriginOpenerPolicy;
return {
getCrossOriginOpenerPolicy: () => {
if (crossOriginOpenerPolicy === undefined) {
return 'undefined';
}
return crossOriginOpenerPolicy;
},
checkCrossOriginOpenerPolicy: async () => {
if (typeof window === 'undefined') {
// Non-browser environment
crossOriginOpenerPolicy = 'non-browser-env';
return;
}
try {
const url = `${window.location.origin}${window.location.pathname}`;
const response = await fetch(url, {
method: 'HEAD',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = response.headers.get('Cross-Origin-Opener-Policy');
crossOriginOpenerPolicy = result !== null && result !== void 0 ? result : 'null';
if (crossOriginOpenerPolicy === 'same-origin') {
console.error(COOP_ERROR_MESSAGE);
}
}
catch (error) {
console.error('Error checking Cross-Origin-Opener-Policy:', error.message);
crossOriginOpenerPolicy = 'error';
}
},
};
};
export const { checkCrossOriginOpenerPolicy, getCrossOriginOpenerPolicy } = createCoopChecker();
//# sourceMappingURL=checkCrossOriginOpenerPolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"checkCrossOriginOpenerPolicy.js","sourceRoot":"","sources":["../../src/util/checkCrossOriginOpenerPolicy.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG;;+GAEoF,CAAC;AAEhH;;;;;;;;;;;;;;GAcG;AACH,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,IAAI,uBAA2C,CAAC;IAEhD,OAAO;QACL,0BAA0B,EAAE,GAAG,EAAE;YAC/B,IAAI,uBAAuB,KAAK,SAAS,EAAE,CAAC;gBAC1C,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,OAAO,uBAAuB,CAAC;QACjC,CAAC;QACD,4BAA4B,EAAE,KAAK,IAAI,EAAE;YACvC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;gBAClC,0BAA0B;gBAC1B,uBAAuB,GAAG,iBAAiB,CAAC;gBAC5C,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACnE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;oBAChC,MAAM,EAAE,MAAM;iBACf,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC5D,CAAC;gBAED,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;gBAClE,uBAAuB,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,MAAM,CAAC;gBAE3C,IAAI,uBAAuB,KAAK,aAAa,EAAE,CAAC;oBAC9C,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;gBACtF,uBAAuB,GAAG,OAAO,CAAC;YACpC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,GAAG,iBAAiB,EAAE,CAAC"}

View File

@@ -0,0 +1,12 @@
import { EncryptedData } from '../core/message/RPCMessage.js';
import { RPCRequest } from '../core/message/RPCRequest.js';
import { RPCResponse } from '../core/message/RPCResponse.js';
export declare function generateKeyPair(): Promise<CryptoKeyPair>;
export declare function deriveSharedSecret(ownPrivateKey: CryptoKey, peerPublicKey: CryptoKey): Promise<CryptoKey>;
export declare function encrypt(sharedSecret: CryptoKey, plainText: string): Promise<EncryptedData>;
export declare function decrypt(sharedSecret: CryptoKey, { iv, cipherText }: EncryptedData): Promise<string>;
export declare function exportKeyToHexString(type: 'public' | 'private', key: CryptoKey): Promise<string>;
export declare function importKeyFromHexString(type: 'public' | 'private', hexString: string): Promise<CryptoKey>;
export declare function encryptContent(content: RPCRequest | RPCResponse, sharedSecret: CryptoKey): Promise<EncryptedData>;
export declare function decryptContent<R extends RPCRequest | RPCResponse>(encryptedData: EncryptedData, sharedSecret: CryptoKey): Promise<R>;
//# sourceMappingURL=cipher.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cipher.d.ts","sourceRoot":"","sources":["../../src/util/cipher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D,wBAAsB,eAAe,IAAI,OAAO,CAAC,aAAa,CAAC,CAS9D;AAED,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,SAAS,EACxB,aAAa,EAAE,SAAS,GACvB,OAAO,CAAC,SAAS,CAAC,CAcpB;AAED,wBAAsB,OAAO,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAYhG;AAED,wBAAsB,OAAO,CAC3B,YAAY,EAAE,SAAS,EACvB,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,aAAa,GAChC,OAAO,CAAC,MAAM,CAAC,CAWjB;AAWD,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,SAAS,CAAC,CAapB;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,UAAU,GAAG,WAAW,EACjC,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,aAAa,CAAC,CAWxB;AAED,wBAAsB,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,WAAW,EACrE,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,CAAC,CAEZ"}

65
node_modules/@coinbase/wallet-sdk/dist/util/cipher.js generated vendored Normal file
View File

@@ -0,0 +1,65 @@
import { hexStringToUint8Array, uint8ArrayToHex } from '../core/type/util.js';
export async function generateKeyPair() {
return crypto.subtle.generateKey({
name: 'ECDH',
namedCurve: 'P-256',
}, true, ['deriveKey']);
}
export async function deriveSharedSecret(ownPrivateKey, peerPublicKey) {
return crypto.subtle.deriveKey({
name: 'ECDH',
public: peerPublicKey,
}, ownPrivateKey, {
name: 'AES-GCM',
length: 256,
}, false, ['encrypt', 'decrypt']);
}
export async function encrypt(sharedSecret, plainText) {
const iv = crypto.getRandomValues(new Uint8Array(12));
const cipherText = await crypto.subtle.encrypt({
name: 'AES-GCM',
iv,
}, sharedSecret, new TextEncoder().encode(plainText));
return { iv, cipherText };
}
export async function decrypt(sharedSecret, { iv, cipherText }) {
const plainText = await crypto.subtle.decrypt({
name: 'AES-GCM',
iv,
}, sharedSecret, cipherText);
return new TextDecoder().decode(plainText);
}
function getFormat(keyType) {
switch (keyType) {
case 'public':
return 'spki';
case 'private':
return 'pkcs8';
}
}
export async function exportKeyToHexString(type, key) {
const format = getFormat(type);
const exported = await crypto.subtle.exportKey(format, key);
return uint8ArrayToHex(new Uint8Array(exported));
}
export async function importKeyFromHexString(type, hexString) {
const format = getFormat(type);
const arrayBuffer = hexStringToUint8Array(hexString).buffer;
return await crypto.subtle.importKey(format, new Uint8Array(arrayBuffer), {
name: 'ECDH',
namedCurve: 'P-256',
}, true, type === 'private' ? ['deriveKey'] : []);
}
export async function encryptContent(content, sharedSecret) {
const serialized = JSON.stringify(content, (_, value) => {
if (!(value instanceof Error))
return value;
const error = value;
return Object.assign(Object.assign({}, (error.code ? { code: error.code } : {})), { message: error.message });
});
return encrypt(sharedSecret, serialized);
}
export async function decryptContent(encryptedData, sharedSecret) {
return JSON.parse(await decrypt(sharedSecret, encryptedData));
}
//# sourceMappingURL=cipher.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file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YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,KAAK,GAAG,KAAmC,CAAC;QAClD,uCACK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAC3C,OAAO,EAAE,KAAK,CAAC,OAAO,IACtB;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,aAA4B,EAC5B,YAAuB;IAEvB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;AAChE,CAAC"}

View File

@@ -0,0 +1,20 @@
import { ConstructorOptions, ProviderInterface, RequestArguments } from '../core/provider/interface.js';
export declare function fetchRPCRequest(request: RequestArguments, rpcUrl: string): Promise<any>;
export interface CBWindow {
top: CBWindow;
ethereum?: CBInjectedProvider;
coinbaseWalletExtension?: CBInjectedProvider;
}
export interface CBInjectedProvider extends ProviderInterface {
isCoinbaseBrowser?: boolean;
setAppInfo?: (...args: unknown[]) => unknown;
}
export declare function getCoinbaseInjectedProvider({ metadata, preference, }: Readonly<ConstructorOptions>): ProviderInterface | undefined;
/**
* Validates the arguments for an invalid request and returns an error if any validation fails.
* Valid request args are defined here: https://eips.ethereum.org/EIPS/eip-1193#request
* @param args The request arguments to validate.
* @returns An error object if the arguments are invalid, otherwise undefined.
*/
export declare function checkErrorForInvalidRequestArgs(args: unknown): asserts args is RequestArguments;
//# sourceMappingURL=provider.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/util/provider.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AAErC,wBAAsB,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAmB9E;AAED,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,QAAQ,CAAC;IACd,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,uBAAuB,CAAC,EAAE,kBAAkB,CAAC;CAC9C;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CAC9C;AAgBD,wBAAgB,2BAA2B,CAAC,EAC1C,QAAQ,EACR,UAAU,GACX,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,GAAG,SAAS,CAkB9D;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAmC/F"}

View File

@@ -0,0 +1,87 @@
import { NAME, VERSION } from '../sdk-info.js';
import { standardErrors } from '../core/error/errors.js';
export async function fetchRPCRequest(request, rpcUrl) {
const requestBody = Object.assign(Object.assign({}, request), { jsonrpc: '2.0', id: crypto.randomUUID() });
const res = await window.fetch(rpcUrl, {
method: 'POST',
body: JSON.stringify(requestBody),
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'X-Cbw-Sdk-Version': VERSION,
'X-Cbw-Sdk-Platform': NAME,
},
});
const { result, error } = await res.json();
if (error)
throw error;
return result;
}
function getCoinbaseInjectedLegacyProvider() {
const window = globalThis;
return window.coinbaseWalletExtension;
}
function getInjectedEthereum() {
var _a, _b;
try {
const window = globalThis;
return (_b = (_a = window.top) === null || _a === void 0 ? void 0 : _a.ethereum) !== null && _b !== void 0 ? _b : window.ethereum;
}
catch (_c) {
return undefined;
}
}
export function getCoinbaseInjectedProvider({ metadata, preference, }) {
var _a, _b;
const { appName, appLogoUrl, appChainIds } = metadata;
if (preference.options !== 'smartWalletOnly') {
const extension = getCoinbaseInjectedLegacyProvider();
if (extension) {
(_a = extension.setAppInfo) === null || _a === void 0 ? void 0 : _a.call(extension, appName, appLogoUrl, appChainIds, preference);
return extension;
}
}
const ethereum = getInjectedEthereum();
if (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isCoinbaseBrowser) {
(_b = ethereum.setAppInfo) === null || _b === void 0 ? void 0 : _b.call(ethereum, appName, appLogoUrl, appChainIds, preference);
return ethereum;
}
return undefined;
}
/**
* Validates the arguments for an invalid request and returns an error if any validation fails.
* Valid request args are defined here: https://eips.ethereum.org/EIPS/eip-1193#request
* @param args The request arguments to validate.
* @returns An error object if the arguments are invalid, otherwise undefined.
*/
export function checkErrorForInvalidRequestArgs(args) {
if (!args || typeof args !== 'object' || Array.isArray(args)) {
throw standardErrors.rpc.invalidParams({
message: 'Expected a single, non-array, object argument.',
data: args,
});
}
const { method, params } = args;
if (typeof method !== 'string' || method.length === 0) {
throw standardErrors.rpc.invalidParams({
message: "'args.method' must be a non-empty string.",
data: args,
});
}
if (params !== undefined &&
!Array.isArray(params) &&
(typeof params !== 'object' || params === null)) {
throw standardErrors.rpc.invalidParams({
message: "'args.params' must be an object or array if provided.",
data: args,
});
}
switch (method) {
case 'eth_sign':
case 'eth_signTypedData_v2':
case 'eth_subscribe':
case 'eth_unsubscribe':
throw standardErrors.provider.unsupportedMethod();
}
}
//# sourceMappingURL=provider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/util/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAOvD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAyB,EAAE,MAAc;IAC7E,MAAM,WAAW,mCACZ,OAAO,KACV,OAAO,EAAE,KAAK,EACd,EAAE,EAAE,MAAM,CAAC,UAAU,E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KAAK,iBAAiB;YACpB,MAAM,cAAc,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;IACtD,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,7 @@
import { Preference } from '../core/provider/interface.js';
/**
* Validates user supplied preferences. Throws if keys are not valid.
* @param preference
*/
export declare function validatePreferences(preference?: Preference): void;
//# sourceMappingURL=validatePreferences.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"validatePreferences.d.ts","sourceRoot":"","sources":["../../src/util/validatePreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,UAAU,QAiB1D"}

View File

@@ -0,0 +1,19 @@
/**
* Validates user supplied preferences. Throws if keys are not valid.
* @param preference
*/
export function validatePreferences(preference) {
if (!preference) {
return;
}
if (!['all', 'smartWalletOnly', 'eoaOnly'].includes(preference.options)) {
throw new Error(`Invalid options: ${preference.options}`);
}
if (preference.attribution) {
if (preference.attribution.auto !== undefined &&
preference.attribution.dataSuffix !== undefined) {
throw new Error(`Attribution cannot contain both auto and dataSuffix properties`);
}
}
}
//# sourceMappingURL=validatePreferences.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"validatePreferences.js","sourceRoot":"","sources":["../../src/util/validatePreferences.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAuB;IACzD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,CAAC,KAAK,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,oBAAoB,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAC3B,IACE,UAAU,CAAC,WAAW,CAAC,IAAI,KAAK,SAAS;YACzC,UAAU,CAAC,WAAW,CAAC,UAAU,KAAK,SAAS,EAC/C,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;AACH,CAAC"}

3
node_modules/@coinbase/wallet-sdk/dist/util/web.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export declare function openPopup(url: URL): Promise<Window>;
export declare function closePopup(popup: Window | null): void;
//# sourceMappingURL=web.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/util/web.ts"],"names":[],"mappings":"AAuBA,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAkDnD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,QAI9C"}

83
node_modules/@coinbase/wallet-sdk/dist/util/web.js generated vendored Normal file
View File

@@ -0,0 +1,83 @@
import { NAME, VERSION } from '../sdk-info.js';
import { getCrossOriginOpenerPolicy } from './checkCrossOriginOpenerPolicy.js';
import { standardErrors } from '../core/error/errors.js';
import { Snackbar } from '../sign/walletlink/relay/ui/components/Snackbar/Snackbar.js';
import { RETRY_SVG_PATH } from '../sign/walletlink/relay/ui/WalletLinkRelayUI.js';
const POPUP_WIDTH = 420;
const POPUP_HEIGHT = 540;
const RETRY_BUTTON = {
isRed: false,
info: 'Retry',
svgWidth: '10',
svgHeight: '11',
path: RETRY_SVG_PATH,
defaultFillRule: 'evenodd',
defaultClipRule: 'evenodd',
};
const POPUP_BLOCKED_MESSAGE = 'Popup was blocked. Try again.';
let snackbar = null;
export function openPopup(url) {
const left = (window.innerWidth - POPUP_WIDTH) / 2 + window.screenX;
const top = (window.innerHeight - POPUP_HEIGHT) / 2 + window.screenY;
appendAppInfoQueryParams(url);
function tryOpenPopup() {
const popupId = `wallet_${crypto.randomUUID()}`;
const popup = window.open(url, popupId, `width=${POPUP_WIDTH}, height=${POPUP_HEIGHT}, left=${left}, top=${top}`);
popup === null || popup === void 0 ? void 0 : popup.focus();
if (!popup) {
return null;
}
return popup;
}
let popup = tryOpenPopup();
// If the popup was blocked, show a snackbar with a retry button
if (!popup) {
const sb = initSnackbar();
return new Promise((resolve, reject) => {
sb.presentItem({
autoExpand: true,
message: POPUP_BLOCKED_MESSAGE,
menuItems: [
Object.assign(Object.assign({}, RETRY_BUTTON), { onClick: () => {
popup = tryOpenPopup();
if (popup) {
resolve(popup);
}
else {
reject(standardErrors.rpc.internal('Popup window was blocked'));
}
sb.clear();
} }),
],
});
});
}
return Promise.resolve(popup);
}
export function closePopup(popup) {
if (popup && !popup.closed) {
popup.close();
}
}
function appendAppInfoQueryParams(url) {
const params = {
sdkName: NAME,
sdkVersion: VERSION,
origin: window.location.origin,
coop: getCrossOriginOpenerPolicy(),
};
for (const [key, value] of Object.entries(params)) {
url.searchParams.append(key, value.toString());
}
}
function initSnackbar() {
if (!snackbar) {
const root = document.createElement('div');
root.className = '-cbwsdk-css-reset';
document.body.appendChild(root);
snackbar = new Snackbar();
snackbar.attach(root);
}
return snackbar;
}
//# sourceMappingURL=web.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/util/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,2DAA2D,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAEhF,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,KAAK;IAC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