Skip to content

Commit

Permalink
fix: fix approvals service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Oct 4, 2024
1 parent 08b150b commit e0cc486
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 15 additions & 8 deletions apps/extension/src/background/approvals/service.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -60,10 +61,11 @@ describe("approvals service", () => {
jest.clearAllMocks();
txStore = new KVStoreMock<PendingTx>("PendingTx");
dataStore = new KVStoreMock<string>("DataStore");
keyRingService = createMockInstance(KeyRingService as any);
keyRingService = createMockInstance(KeyRingService);
const vaultService: jest.Mocked<VaultService> = createMockInstance(
VaultService as any
);
chainService = createMockInstance(ChainsService);
const broadcaster: jest.Mocked<ExtensionBroadcaster> =
createMockInstance(ExtensionBroadcaster);
localStorage = new LocalStorage(new KVStoreMock("LocalStorage"));
Expand Down Expand Up @@ -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);
Expand All @@ -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();
});
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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]);
Expand All @@ -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(
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion apps/namadillo/src/App/Transfer/SelectedWallet.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -16,12 +18,14 @@ export const SelectedWallet = ({
isShielded,
}: SelectedWalletProps): JSX.Element => {
const [walletAddress, setWalletAddress] = useState("");
const { data: chain } = useAtomValue(chainParametersAtom);

const loadAccounts = async (): Promise<void> => {
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) {
Expand Down

0 comments on commit e0cc486

Please sign in to comment.