From da3ac81cfb22a5c1383df4d201e97bdf34fc91ab Mon Sep 17 00:00:00 2001 From: Aristides Staffieri Date: Wed, 10 Jan 2024 09:45:23 -0700 Subject: [PATCH] updates tests and tweaks asset detail from master merge --- .../components/account/AssetDetail/index.tsx | 4 +-- .../accountHistory/HistoryItem/index.tsx | 2 +- .../signTransaction/Operations/index.tsx | 2 +- .../views/__tests__/ManageAssets.test.tsx | 29 ++++++++++++------- .../src/popup/views/__tests__/Swap.test.tsx | 15 ++++++---- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/extension/src/popup/components/account/AssetDetail/index.tsx b/extension/src/popup/components/account/AssetDetail/index.tsx index a78677a67c..c6ba7c2795 100644 --- a/extension/src/popup/components/account/AssetDetail/index.tsx +++ b/extension/src/popup/components/account/AssetDetail/index.tsx @@ -4,7 +4,7 @@ import { BigNumber } from "bignumber.js"; import { useTranslation } from "react-i18next"; import { IconButton, Icon, Notification } from "@stellar/design-system"; -import { HorizonOperation, AssetType } from "@shared/api/types"; +import { HorizonOperation, AssetType, TokenBalance } from "@shared/api/types"; import { NetworkDetails } from "@shared/constants/stellar"; import { getAvailableBalance, @@ -174,7 +174,7 @@ export const AssetDetail = ({ assetDomain={assetDomain} contractId={ balance && "decimals" in balance - ? balance.token.issuer.key + ? (balance as TokenBalance).token.issuer.key : undefined } /> diff --git a/extension/src/popup/components/accountHistory/HistoryItem/index.tsx b/extension/src/popup/components/accountHistory/HistoryItem/index.tsx index 2dd15c48f5..e2a18ec586 100644 --- a/extension/src/popup/components/accountHistory/HistoryItem/index.tsx +++ b/extension/src/popup/components/accountHistory/HistoryItem/index.tsx @@ -238,7 +238,7 @@ export const HistoryItem = ({ try { const response = await fetch( - `${INDEXER_URL}/token-details/${attrs.contractId}?pub_key=${publicKey}&horizon_url=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`, + `${INDEXER_URL}/token-details/${attrs.contractId}?pub_key=${publicKey}&network=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`, ); if (!response.ok) { diff --git a/extension/src/popup/components/signTransaction/Operations/index.tsx b/extension/src/popup/components/signTransaction/Operations/index.tsx index aa25f2897b..1d7068cd33 100644 --- a/extension/src/popup/components/signTransaction/Operations/index.tsx +++ b/extension/src/popup/components/signTransaction/Operations/index.tsx @@ -355,7 +355,7 @@ export const Operations = ({ if (!contractId) return; const fetchContractDecimals = async () => { const response = await fetch( - `${INDEXER_URL}/token-details/${contractId}?pub_key=${publicKey}&horizon_url=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`, + `${INDEXER_URL}/token-details/${contractId}?pub_key=${publicKey}&network=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`, ); if (!response.ok) { throw new Error("failed to fetch token details"); diff --git a/extension/src/popup/views/__tests__/ManageAssets.test.tsx b/extension/src/popup/views/__tests__/ManageAssets.test.tsx index a30fa8cc93..af82368dd3 100644 --- a/extension/src/popup/views/__tests__/ManageAssets.test.tsx +++ b/extension/src/popup/views/__tests__/ManageAssets.test.tsx @@ -64,10 +64,11 @@ const manageAssetsMockBalances = { } as any) as Balances, isFunded: true, subentryCount: 1, + tokensWithNoBalance: [], }; jest - .spyOn(ApiInternal, "getAccountBalances") + .spyOn(ApiInternal, "getAccountIndexerBalances") .mockImplementation(() => Promise.resolve(manageAssetsMockBalances)); jest @@ -115,16 +116,6 @@ jest.spyOn(ApiInternal, "signFreighterTransaction").mockImplementation(() => }), ); -jest - .spyOn(ApiInternal, "submitFreighterTransaction") - .mockImplementation(({ networkDetails }) => { - if (networkDetails.networkName === "Test Net Reject") { - return Promise.reject(Error("Request failed")); - } - - return Promise.resolve({}); - }); - jest.spyOn(UseNetworkFees, "useNetworkFees").mockImplementation(() => ({ recommendedFee: "0.00001", networkCongestion: UseNetworkFees.NetworkCongestion.MEDIUM, @@ -239,6 +230,15 @@ describe("Manage assets", () => { jest.clearAllMocks(); }); + beforeEach(() => { + jest.spyOn(global, "fetch").mockImplementation(() => + Promise.resolve({ + ok: true, + json: async () => ({}), + } as any), + ); + }); + it("renders manage assets view initial state", async () => { await initView(); @@ -338,6 +338,13 @@ describe("Manage assets", () => { }); it("show error view when removing asset with balance", async () => { + jest.spyOn(global, "fetch").mockImplementation(() => + Promise.resolve({ + ok: false, + json: async () => ({}), + } as any), + ); + await initView(true); expect(screen.getByTestId("AppHeaderPageTitle")).toHaveTextContent( diff --git a/extension/src/popup/views/__tests__/Swap.test.tsx b/extension/src/popup/views/__tests__/Swap.test.tsx index c357c07737..223a9dfc16 100644 --- a/extension/src/popup/views/__tests__/Swap.test.tsx +++ b/extension/src/popup/views/__tests__/Swap.test.tsx @@ -53,10 +53,11 @@ export const swapMockBalances = { } as any) as Balances, isFunded: true, subentryCount: 1, + tokensWithNoBalance: [], }; jest - .spyOn(ApiInternal, "getAccountBalances") + .spyOn(ApiInternal, "getAccountIndexerBalances") .mockImplementation(() => Promise.resolve(swapMockBalances)); jest.spyOn(ApiInternal, "signFreighterTransaction").mockImplementation(() => @@ -66,10 +67,6 @@ jest.spyOn(ApiInternal, "signFreighterTransaction").mockImplementation(() => }), ); -jest - .spyOn(ApiInternal, "submitFreighterTransaction") - .mockImplementation(() => Promise.resolve({})); - jest.spyOn(UseNetworkFees, "useNetworkFees").mockImplementation(() => ({ recommendedFee: "0.00001", networkCongestion: UseNetworkFees.NetworkCongestion.MEDIUM, @@ -133,6 +130,14 @@ jest.mock("stellar-sdk", () => { const publicKey = "GCXRLIZUQNZ3YYJDGX6Z445P7FG5WXT7UILBO5CFIYYM7Z7YTIOELC6O"; describe("Swap", () => { + beforeEach(() => { + jest.spyOn(global, "fetch").mockImplementation(() => + Promise.resolve({ + ok: true, + json: async () => ({}), + } as any), + ); + }); beforeEach(async () => { const history = createMemoryHistory(); history.push(ROUTES.swap);