Skip to content

Commit

Permalink
update (#1151)
Browse files Browse the repository at this point in the history
* update

* window.setPopupUrl
  • Loading branch information
fan-zhang-sv authored Apr 1, 2024
1 parent e041289 commit 1de85fe
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/testapp/src/context/CBWSDKReactContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CoinbaseWalletSDK as CoinbaseWalletSDK40 } from '@coinbase/wallet-sdk';
import { SignRequestHandler } from '@coinbase/wallet-sdk/dist/sign/SignRequestHandler';
import { CoinbaseWalletSDK as CoinbaseWalletSDK37 } from '@coinbase/wallet-sdk-3.7';
import { CoinbaseWalletSDK as CoinbaseWalletSDK39 } from '@coinbase/wallet-sdk-3.9';
import React, { useEffect, useMemo } from 'react';
Expand All @@ -17,12 +18,25 @@ export type SDKVersionType = (typeof sdkVersions)[number];
const SELECTED_SCW_URL_KEY = 'scw_url';
export const scwUrls = [
'https://keys.coinbase.com/connect',
'https://scw-dev.cbhq.net/connect',
'https://scw-staging.cbhq.net/connect',
'http://localhost:3005/connect',
] as const;
export type ScwUrlType = (typeof scwUrls)[number];

declare global {
interface Window {
setPopupUrl: (url: string) => void;
}
}

if (typeof window !== 'undefined') {
window.setPopupUrl = (url: string) => {
const handler = (window.ethereum as any).handlers.find(
(h: any) => h instanceof SignRequestHandler
);
handler.popupCommunicator.url = new URL(url);
};
}

export function CBWSDKReactContextProvider({ children }: CBWSDKProviderProps) {
const [version, setVersion] = React.useState<SDKVersionType | undefined>(undefined);
const [smartWalletOnly, setSmartWalletOnly] = React.useState<boolean | undefined>(undefined);
Expand Down Expand Up @@ -81,7 +95,7 @@ export function CBWSDKReactContextProvider({ children }: CBWSDKProviderProps) {

useEffect(() => {
if (version === '4.0' && scwUrl) {
(window.ethereum as any).handlers[1].popupCommunicator.url = new URL(scwUrl);
window.setPopupUrl?.(scwUrl);
}
}, [version, scwUrl, sdk]);

Expand Down

0 comments on commit 1de85fe

Please sign in to comment.