Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/wallet-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/wallet-sdk",
"version": "3.9.7",
"version": "3.9.8",
"description": "Coinbase Wallet JavaScript SDK",
"keywords": [
"cipher",
Expand Down
8 changes: 7 additions & 1 deletion packages/wallet-sdk/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import BN from 'bn.js';

import { getCommerceCorrelationId } from '../telemetry/commerceCorrelationId';
import { standardErrors } from './error';
import { AddressString, BigIntString, HexString, IntNumber, RegExpString } from './type';

Expand Down Expand Up @@ -133,7 +134,7 @@

export function ensureBN(val: unknown): BN {
if (val !== null && (BN.isBN(val) || isBigNumber(val))) {
return new BN((val as any).toString(10), 10);

Check warning on line 137 in packages/wallet-sdk/src/core/util.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type

Check warning on line 137 in packages/wallet-sdk/src/core/util.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type
}
if (typeof val === 'number') {
return new BN(ensureIntNumber(val));
Expand Down Expand Up @@ -162,10 +163,10 @@
}

export function isBigNumber(val: unknown): boolean {
if (val == null || typeof (val as any).constructor !== 'function') {

Check warning on line 166 in packages/wallet-sdk/src/core/util.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type

Check warning on line 166 in packages/wallet-sdk/src/core/util.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type
return false;
}
const { constructor } = val as any;

Check warning on line 169 in packages/wallet-sdk/src/core/util.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type

Check warning on line 169 in packages/wallet-sdk/src/core/util.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type
return typeof constructor.config === 'function' && typeof constructor.EUCLID === 'number';
}

Expand Down Expand Up @@ -200,16 +201,21 @@
serverUrl: string,
isParentConnection: boolean,
version: string,
chainId: number
chainId: number,
isMobileRelay?: boolean | undefined
): string {
const sessionIdKey = isParentConnection ? 'parent-id' : 'id';
const commerceCorrelationId = getCommerceCorrelationId();

const query = new URLSearchParams({
[sessionIdKey]: sessionId,
secret: sessionSecret,
server: serverUrl,
v: version,
chainId: chainId.toString(),
pl: 't', // this is custom build of SDK for Payment Link
...(isMobileRelay ? { m: 't' } : {}),
...(commerceCorrelationId ? { cid: commerceCorrelationId } : {}),
}).toString();

const qrUrl = `${serverUrl}/#/link?${query}`;
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
export { CoinbaseWalletProvider } from './provider/CoinbaseWalletProvider';
export default CoinbaseWalletSDK;

export { setCommerceCorrelationId } from './telemetry/commerceCorrelationId';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being used here?


declare global {
interface Window {
CoinbaseWalletSDK: typeof CoinbaseWalletSDK;
Expand All @@ -15,7 +17,7 @@
/**
* For CoinbaseWalletSDK, window.ethereum is `CoinbaseWalletProvider`
*/
ethereum?: any;

Check warning on line 20 in packages/wallet-sdk/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type

Check warning on line 20 in packages/wallet-sdk/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint Check

Unexpected any. Specify a different type
coinbaseWalletExtension?: CoinbaseWalletProvider;

/**
Expand Down
15 changes: 11 additions & 4 deletions packages/wallet-sdk/src/provider/CoinbaseWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import { RelayEventManager } from '../relay/RelayEventManager';
import { Session } from '../relay/Session';
import { EthereumTransactionParams } from '../relay/walletlink/type/EthereumTransactionParams';
import { isErrorResponse, Web3Response } from '../relay/walletlink/type/Web3Response';
import { getCommerceCorrelationId } from '../telemetry/commerceCorrelationId';
import {
logRequestCompleted,
logRequestError,
logRequestStarted,
} from '../telemetry/events/provider';
import { parseErrorMessageFromAny } from '../telemetry/utils';
import eip712 from '../vendor-js/eth-eip712-util';
import { DiagnosticLogger, EVENTS } from './DiagnosticLogger';
import { FilterPolyfill } from './FilterPolyfill';
Expand All @@ -37,8 +44,6 @@ import {
SubscriptionResult,
} from './SubscriptionManager';
import { RequestArguments, Web3Provider } from './Web3Provider';
import { logRequestCompleted, logRequestError, logRequestStarted } from '../telemetry/events/provider';
import { parseErrorMessageFromAny } from '../telemetry/utils';

const DEFAULT_CHAIN_ID_KEY = 'DefaultChainId';
const DEFAULT_JSON_RPC_URL = 'DefaultJsonRpcUrl';
Expand Down Expand Up @@ -471,17 +476,19 @@ export class CoinbaseWalletProvider extends EventEmitter implements Web3Provider
}

public async request<T>(args: RequestArguments): Promise<T> {
logRequestStarted({ method: args.method });
const commerceCorrelationId = getCommerceCorrelationId();
logRequestStarted({ method: args.method, commerceCorrelationId });
try {
const result = await this._request<T>(args).catch((error) => {
throw serializeError(error, args.method);
});
logRequestCompleted({ method: args.method });
logRequestCompleted({ method: args.method, commerceCorrelationId });
return result;
} catch (error) {
logRequestError({
method: args.method,
errorMessage: parseErrorMessageFromAny(error),
commerceCorrelationId,
});
return Promise.reject(serializeError(error, args.method));
}
Expand Down
22 changes: 20 additions & 2 deletions packages/wallet-sdk/src/relay/mobile/MobileRelay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getLocation } from '../../core/util';
import { createQrUrl, getLocation } from '../../core/util';
import { getCommerceCorrelationId } from '../../telemetry/commerceCorrelationId';
import { logMobileWalletLinkRequestAccountsDeeplinked } from '../../telemetry/events/walletlink';
import { CancelablePromise } from '../RelayAbstract';
import { WalletLinkResponseEventData } from '../walletlink/type/WalletLinkEventData';
import { Web3Request } from '../walletlink/type/Web3Request';
Expand Down Expand Up @@ -41,10 +43,13 @@ export class MobileRelay extends WalletLinkRelay {
// For mobile relay requests, open the Coinbase Wallet app
switch (request.method) {
case 'requestEthereumAccounts':
case 'connectAndSignIn':
case 'connectAndSignIn': {
navigatedToCBW = true;
const commerceCorrelationId = getCommerceCorrelationId();
logMobileWalletLinkRequestAccountsDeeplinked({ commerceCorrelationId });
this.ui.openCoinbaseWalletDeeplink(this.getQRCodeUrl());
break;
}
case 'switchEthereumChain':
// switchEthereumChain doesn't need to open the app
return;
Expand Down Expand Up @@ -73,6 +78,19 @@ export class MobileRelay extends WalletLinkRelay {
}
}

// override
getQRCodeUrl() {
return createQrUrl(
this._session.id,
this._session.secret,
this.linkAPIUrl,
false,
this.options.version,
this.dappDefaultChain,
true // adding isMobileWalletlink flag to the query params
);
}

// override
handleWeb3ResponseMessage(message: WalletLinkResponseEventData) {
super.handleWeb3ResponseMessage(message);
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet-sdk/src/relay/walletlink/WalletLinkRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export interface WalletLinkRelayOptions {
export class WalletLinkRelay extends RelayAbstract implements WalletLinkConnectionUpdateListener {
private static accountRequestCallbackIds = new Set<string>();

private readonly linkAPIUrl: string;
protected readonly linkAPIUrl: string;
protected readonly storage: ScopedLocalStorage;
private _session: Session;
protected _session: Session;
private readonly relayEventManager: RelayEventManager;
protected readonly diagnostic?: DiagnosticLogger;
protected connection: WalletLinkConnection;
private accountsCallback: ((account: string[], isDisconnect?: boolean) => void) | null = null;
private chainCallbackParams = { chainId: '', jsonRpcUrl: '' }; // to implement distinctUntilChanged
private chainCallback: ((chainId: string, jsonRpcUrl: string) => void) | null = null;
protected dappDefaultChain = 1;
private readonly options: WalletLinkRelayOptions;
protected readonly options: WalletLinkRelayOptions;

protected ui: RelayUI;

Expand Down
9 changes: 9 additions & 0 deletions packages/wallet-sdk/src/telemetry/commerceCorrelationId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let commerceCorrelationId: string | null = null;

export function setCommerceCorrelationId(id: string) {
commerceCorrelationId = id;
}

export function getCommerceCorrelationId() {
return commerceCorrelationId;
}
21 changes: 19 additions & 2 deletions packages/wallet-sdk/src/telemetry/events/provider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { ActionType, AnalyticsEventImportance, ComponentType, logEvent } from '../logEvent';

export function logRequestStarted({ method }: { method: string }) {
export function logRequestStarted({
method,
commerceCorrelationId,
}: {
method: string;
commerceCorrelationId: string | null;
}) {
logEvent(
'commerce.sdk.request_started',
{
action: ActionType.measurement,
componentType: ComponentType.unknown,
method,
commerceCorrelationId: commerceCorrelationId ?? '',
},
AnalyticsEventImportance.high
);
Expand All @@ -15,9 +22,11 @@ export function logRequestStarted({ method }: { method: string }) {
export function logRequestError({
method,
errorMessage,
commerceCorrelationId,
}: {
method: string;
errorMessage: string;
commerceCorrelationId: string | null;
}) {
logEvent(
'commerce.sdk.request_error',
Expand All @@ -26,18 +35,26 @@ export function logRequestError({
componentType: ComponentType.unknown,
method,
errorMessage,
commerceCorrelationId: commerceCorrelationId ?? '',
},
AnalyticsEventImportance.high
);
}

export function logRequestCompleted({ method }: { method: string }) {
export function logRequestCompleted({
method,
commerceCorrelationId,
}: {
method: string;
commerceCorrelationId: string | null;
}) {
logEvent(
'commerce.sdk.request_completed',
{
action: ActionType.measurement,
componentType: ComponentType.unknown,
method,
commerceCorrelationId: commerceCorrelationId ?? '',
},
AnalyticsEventImportance.high
);
Expand Down
16 changes: 16 additions & 0 deletions packages/wallet-sdk/src/telemetry/events/walletlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@ export const logWalletLinkConnectionFetchUnseenEventsFailed = () => {
},
AnalyticsEventImportance.high
);
};

export const logMobileWalletLinkRequestAccountsDeeplinked = ({
commerceCorrelationId,
}: {
commerceCorrelationId: string | null;
}) => {
logEvent(
'commerce.walletlink_connection.mobile_request_accounts_deeplinked',
{
action: ActionType.measurement,
componentType: ComponentType.unknown,
commerceCorrelationId: commerceCorrelationId ?? '',
},
AnalyticsEventImportance.high
);
};
2 changes: 1 addition & 1 deletion packages/wallet-sdk/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const LIB_VERSION = '3.9.7';
export const LIB_VERSION = '3.9.8';
Loading