From e0cc4866526c0f871374d7b1df2268c262967a1b Mon Sep 17 00:00:00 2001 From: "Justin R. Evans" Date: Fri, 27 Sep 2024 13:02:55 -0400 Subject: [PATCH] fix: fix approvals service tests --- .../src/background/approvals/service.test.ts | 23 ++++++++++++------- .../src/App/Transfer/SelectedWallet.tsx | 6 ++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/extension/src/background/approvals/service.test.ts b/apps/extension/src/background/approvals/service.test.ts index 6e2a06ab1..c2c9892ba 100644 --- a/apps/extension/src/background/approvals/service.test.ts +++ b/apps/extension/src/background/approvals/service.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { chains } from "@namada/chains"; import { WrapperTxMsgValue } from "@namada/types"; import { ChainsService } from "background/chains"; import { KeyRingService } from "background/keyring"; @@ -60,10 +61,11 @@ describe("approvals service", () => { jest.clearAllMocks(); txStore = new KVStoreMock("PendingTx"); dataStore = new KVStoreMock("DataStore"); - keyRingService = createMockInstance(KeyRingService as any); + keyRingService = createMockInstance(KeyRingService); const vaultService: jest.Mocked = createMockInstance( VaultService as any ); + chainService = createMockInstance(ChainsService); const broadcaster: jest.Mocked = createMockInstance(ExtensionBroadcaster); localStorage = new LocalStorage(new KVStoreMock("LocalStorage")); @@ -264,7 +266,7 @@ describe("approvals service", () => { describe("approveConnection", () => { it("should approve connection if it's not already approved", async () => { const interfaceOrigin = "origin"; - const chainId = "chainId"; + const chainId = chains.namada.chainId; const tabId = 1; jest.spyOn(service, "isConnectionApproved").mockResolvedValue(false); @@ -281,10 +283,11 @@ describe("approvals service", () => { expect(service["launchApprovalPopup"]).toHaveBeenCalledWith( "/approve-connection", - { interfaceOrigin } + { interfaceOrigin, chainId } ); expect(service.isConnectionApproved).toHaveBeenCalledWith( - interfaceOrigin + interfaceOrigin, + chainId ); await expect(promise).resolves.toBeDefined(); }); @@ -366,7 +369,7 @@ describe("approvals service", () => { describe("approveDisconnection", () => { it("should approve disconnection if there is a connection already approved", async () => { const interfaceOrigin = "origin"; - const chainId = ""; + const chainId = chains.namada.chainId; const tabId = 1; jest.spyOn(service, "isConnectionApproved").mockResolvedValue(true); @@ -386,14 +389,15 @@ describe("approvals service", () => { { interfaceOrigin } ); expect(service.isConnectionApproved).toHaveBeenCalledWith( - interfaceOrigin + interfaceOrigin, + chainId ); await expect(promise).resolves.toBeDefined(); }); it("should not approve disconnection if it is NOT already approved", async () => { const interfaceOrigin = "origin"; - const chainId = ""; + const chainId = "chainId"; jest.spyOn(service, "isConnectionApproved").mockResolvedValue(false); await expect( @@ -559,7 +563,8 @@ describe("approvals service", () => { describe("isConnectionApproved", () => { it("should return true if origin is approved", async () => { const origin = "origin"; - const chainId = "chainId"; + const chainId = chains.namada.chainId; + jest.spyOn(chainService, "getChain").mockResolvedValue(chains.namada); jest .spyOn(localStorage, "getApprovedOrigins") .mockResolvedValue([origin]); @@ -572,6 +577,7 @@ describe("approvals service", () => { it("should return false if origin is not approved", async () => { const origin = "origin"; const chainId = "chainId"; + jest.spyOn(chainService, "getChain").mockResolvedValue(chains.namada); jest.spyOn(localStorage, "getApprovedOrigins").mockResolvedValue([]); await expect(service.isConnectionApproved(origin, chainId)).resolves.toBe( @@ -582,6 +588,7 @@ describe("approvals service", () => { it("should return false if there are no origins in store", async () => { const origin = "origin"; const chainId = "chainId"; + jest.spyOn(chainService, "getChain").mockResolvedValue(chains.namada); jest .spyOn(localStorage, "getApprovedOrigins") .mockResolvedValue(undefined); diff --git a/apps/namadillo/src/App/Transfer/SelectedWallet.tsx b/apps/namadillo/src/App/Transfer/SelectedWallet.tsx index bc8197db5..6c61fe329 100644 --- a/apps/namadillo/src/App/Transfer/SelectedWallet.tsx +++ b/apps/namadillo/src/App/Transfer/SelectedWallet.tsx @@ -1,6 +1,8 @@ import { integrations } from "@namada/integrations"; import { shortenAddress } from "@namada/utils"; +import { chainParametersAtom } from "atoms/chain"; import clsx from "clsx"; +import { useAtomValue } from "jotai"; import { useEffect, useState } from "react"; import { WalletProvider } from "types"; @@ -16,12 +18,14 @@ export const SelectedWallet = ({ isShielded, }: SelectedWalletProps): JSX.Element => { const [walletAddress, setWalletAddress] = useState(""); + const { data: chain } = useAtomValue(chainParametersAtom); const loadAccounts = async (): Promise => { try { const integration = integrations[wallet.id]; integration.detect(); - await integration.connect(); + // TODO: This likely isn't correct: + await integration.connect(chain!.chainId); const accounts = await integration.accounts(); if (accounts && accounts.length > 0) {