Skip to content

Commit

Permalink
fix: chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Sep 8, 2023
1 parent 7fc8163 commit bbbc715
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rabby-wallet/eth-lattice-keyring": "^1.0.5",
"@rabby-wallet/eth-simple-keyring": "^4.2.1",
"@rabby-wallet/eth-trezor-keyring": "^2.2.0",
"@rabby-wallet/eth-walletconnect-keyring": "^2.0.0-beta.3",
"@rabby-wallet/eth-walletconnect-keyring": "2.0.0-beta.4",
"@rabby-wallet/eth-watch-keyring": "^1.0.0",
"@rabby-wallet/gnosis-sdk": "^1.3.5",
"@rabby-wallet/page-provider": "^0.1.20",
Expand Down
12 changes: 8 additions & 4 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,11 @@ export class WalletController extends BaseController {
return null;
};

initWalletConnect = async (brandName: string, curStashId?: number | null) => {
initWalletConnect = async (
brandName: string,
curStashId?: number | null,
chainId = 1
) => {
let keyring: WalletConnectKeyring, isNewKey;
const keyringType = KEYRING_CLASS.WALLETCONNECT;
try {
Expand All @@ -1725,14 +1729,14 @@ export class WalletController extends BaseController {
keyring = new WalletConnect(GET_WALLETCONNECT_CONFIG());
isNewKey = true;
}
const { uri } = await keyring.initConnector(brandName, 1);
const { uri } = await keyring.initConnector(brandName, chainId);
let stashId = curStashId;
if (isNewKey) {
stashId = this.addKeyringToStash(keyring);
eventBus.addEventListener(
EVENTS.WALLETCONNECT.INIT,
({ address, brandName }) => {
(keyring as WalletConnectKeyring).init(address, brandName);
({ address, brandName, chainId }) => {
(keyring as WalletConnectKeyring).init(address, brandName, chainId);
}
);
(keyring as WalletConnectKeyring).on('inited', (uri) => {
Expand Down
4 changes: 2 additions & 2 deletions src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ export class KeyringService extends EventEmitter {
if (keyring.type === KEYRING_CLASS.WALLETCONNECT) {
eventBus.addEventListener(
EVENTS.WALLETCONNECT.INIT,
({ address, brandName }) => {
(keyring as WalletConnectKeyring).init(address, brandName);
({ address, brandName, chainId }) => {
(keyring as WalletConnectKeyring).init(address, brandName, chainId);
}
);
(keyring as WalletConnectKeyring).on('inited', (uri) => {
Expand Down
1 change: 1 addition & 0 deletions src/ui/utils/WalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const useCommonPopupViewState = () => {
address: string;
brandName: string;
realBrandName?: string;
chainId?: number;
}>();
const [data, setData] = useState<any>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const WalletConnectAccount: React.FC<Props> = ({ account, chain }) => {
address,
brandName,
realBrandName,
chainId: chain?.id,
});
if (tipStatus === 'DISCONNECTED') {
activePopup('WalletConnect');
Expand Down
32 changes: 7 additions & 25 deletions src/ui/views/WalletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useSessionStatus } from '@/ui/component/WalletConnect/useSessionStatus'
import { useBrandNameHasWallet } from '@/ui/component/WalletConnect/useBrandNameHasWallet';
import { getOriginFromUrl } from '@/utils';
import { ConnectedSite } from '@/background/service/permission';
import { findChainByEnum } from '@/utils/chain';

const WalletConnectName = WALLET_BRAND_CONTENT['WALLETCONNECT']?.name;

Expand All @@ -38,14 +39,14 @@ const WalletConnectTemplate = () => {
Parameters<typeof run> | undefined
>();
const [curStashId, setCurStashId] = useState<number | null>();
const [site, setSite] = useState<ConnectedSite | null>(null);
const siteRef = React.useRef<ConnectedSite | null>(null);

const getCurrentSite = useCallback(async () => {
const tab = await getCurrentTab();
if (!tab.id || !tab.url) return;
const domain = getOriginFromUrl(tab.url);
const current = await wallet.getCurrentSite(tab.id, domain);
setSite(current);
siteRef.current = current;
}, []);

const [run, loading] = useWalletRequest(wallet.importWalletConnect, {
Expand Down Expand Up @@ -89,9 +90,11 @@ const WalletConnectTemplate = () => {
};

const handleImportByWalletconnect = async () => {
const chain = findChainByEnum(siteRef.current?.chain);
const { uri, stashId } = await wallet.initWalletConnect(
brand.brand,
curStashId
curStashId,
chain?.id
);
setCurStashId(stashId);
setWalletconnectUri(uri!);
Expand Down Expand Up @@ -178,28 +181,7 @@ const WalletConnectTemplate = () => {
}, [sessionStatus]);

const init = async () => {
// const cache = await wallet.getPageStateCache();
// if (cache && cache.path === history.location.pathname) {
// const { states } = cache;
// if (states.uri) setWalletconnectUri(states.uri);
// if (states.brand) {
// setBrand(states.brand);
// }
// if (states.data) {
// setRunParams([
// states.data.payload,
// states.brand.brand,
// states.bridgeURL,
// states.stashId,
// ]);
// }
// if (states.bridgeURL && states.bridgeURL !== bridgeURL) {
// setBridgeURL(states.bridgeURL);
// }
// } else {
// handleImportByWalletconnect();
// }

await getCurrentSite();
handleImportByWalletconnect();
setReady(true);
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3452,10 +3452,10 @@
ethereumjs-util "^7.1.5"
hdkey "0.8.0"

"@rabby-wallet/eth-walletconnect-keyring@^2.0.0-beta.3":
version "2.0.0-beta.3"
resolved "https://registry.yarnpkg.com/@rabby-wallet/eth-walletconnect-keyring/-/eth-walletconnect-keyring-2.0.0-beta.3.tgz#12f15db257ff069b5bf4627ce1c71b5a7f895b18"
integrity sha512-kZdYY0lzWpuKskcQCmte4iEHJPXLRnpgr3xJTA6JsWYjEJ/ldAtFostCYVsxTpHv7+VuPhkMibRWfoxdZLoXBg==
"@rabby-wallet/[email protected].4":
version "2.0.0-beta.4"
resolved "https://registry.yarnpkg.com/@rabby-wallet/eth-walletconnect-keyring/-/eth-walletconnect-keyring-2.0.0-beta.4.tgz#c8ed76c031396534c0eeb62ad7df9de65271cde8"
integrity sha512-L3+DvLAarJoiSr2DaOVvZQM6gM7j7Xu7ao6ZeHafo5HFSBQ9Ruj8UDip80LMsGaGcfvHDq3G4BU8V2lutiH/uA==
dependencies:
"@ethereumjs/tx" "^3.5.2"
"@walletconnect/sign-client" "^2.10.0"
Expand Down

0 comments on commit bbbc715

Please sign in to comment.