Skip to content

Commit 21eaed9

Browse files
authored
after adding/removing asset: update status (#2285)
1 parent 805253d commit 21eaed9

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

extension/e2e-tests/addAsset.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, expectPageToHaveScreenshot } from "./test-fixtures";
2-
import { loginToTestAccount } from "./helpers/login";
2+
import { loginAndFund, loginToTestAccount } from "./helpers/login";
33
import { TEST_TOKEN_ADDRESS, USDC_TOKEN_ADDRESS } from "./helpers/test-token";
44
import {
55
stubAccountBalances,
@@ -116,6 +116,51 @@ test("Adding token on Futurenet", async ({ page, extensionId, context }) => {
116116
await page.getByText("Add an asset").click({ force: true });
117117
await expect(page.getByTestId("search-token-input")).toBeVisible();
118118
});
119+
test("Adding classic asset on Testnet", async ({ page, extensionId }) => {
120+
test.slow();
121+
await loginAndFund({ page, extensionId });
122+
123+
await page.getByTestId("account-options-dropdown").click();
124+
await page.getByText("Manage assets").click();
125+
await expect(page.getByText("Your assets")).toBeVisible();
126+
await page.getByText("Add an asset").click({ force: true });
127+
await page
128+
.getByTestId("search-asset-input")
129+
.fill("GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5");
130+
await expect(page.getByText("USDC")).toBeVisible();
131+
132+
await page.getByTestId("ManageAssetRowButton").click();
133+
await expect(
134+
page.getByTestId("SignTransaction__TrustlineRow__Asset"),
135+
).toHaveText("USDC");
136+
await expect(
137+
page.getByTestId("SignTransaction__TrustlineRow__Type"),
138+
).toHaveText("Add Trustline");
139+
await page.getByRole("button", { name: "Confirm" }).click();
140+
await expect(
141+
page.getByTestId("ManageAssetRowButton__ellipsis-USDC"),
142+
).toBeVisible();
143+
144+
// now go back and remove this asset
145+
await page.getByTestId("BackButton").click();
146+
await expect(page.getByText("Your assets")).toBeVisible();
147+
await expect(page.getByTestId("ManageAssetCode")).toHaveText("USDC");
148+
await expect(page.getByTestId("ManageAssetDomain")).toHaveText("centre.io");
149+
await page.getByTestId("ManageAssetRowButton__ellipsis-USDC").click();
150+
await page.getByText("Remove asset").click();
151+
await expect(
152+
page.getByTestId("SignTransaction__TrustlineRow__Asset"),
153+
).toHaveText("USDC");
154+
await expect(
155+
page.getByTestId("SignTransaction__TrustlineRow__Type"),
156+
).toHaveText("Remove Trustline");
157+
await page.getByRole("button", { name: "Confirm" }).click();
158+
await expect(
159+
page.getByText(
160+
"You have no assets added. Get started by adding an asset below.",
161+
),
162+
).toBeVisible();
163+
});
119164
test.afterAll(async ({ page, extensionId }) => {
120165
if (
121166
process.env.IS_INTEGRATION_MODE &&

extension/src/popup/components/manageAssets/ChooseAsset/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next";
66

77
import { ROUTES } from "popup/constants/routes";
88
import { settingsSorobanSupportedSelector } from "popup/ducks/settings";
9+
import { balancesSelector } from "popup/ducks/cache";
910
import { SubviewHeader } from "popup/components/SubviewHeader";
1011
import { View } from "popup/basics/layout/View";
1112

@@ -31,6 +32,7 @@ export const ChooseAsset = ({
3132
const { t } = useTranslation();
3233
const location = useLocation();
3334
const isSorobanSuported = useSelector(settingsSorobanSupportedSelector);
35+
const cachedBalances = useSelector(balancesSelector);
3436

3537
const ManageAssetRowsWrapperRef = useRef<HTMLDivElement>(null);
3638

@@ -44,12 +46,14 @@ export const ChooseAsset = ({
4446
domainState.state === RequestState.LOADING;
4547

4648
useEffect(() => {
49+
/* This effect is keyed off of changes to cachedBalances as this let's us update the UI when an asset is removed */
4750
const getData = async () => {
4851
await fetchData(true);
4952
};
53+
5054
getData();
5155
// eslint-disable-next-line react-hooks/exhaustive-deps
52-
}, []);
56+
}, [cachedBalances]);
5357

5458
if (isLoading) {
5559
return (

extension/src/popup/components/manageAssets/SearchAsset/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Navigate, useLocation } from "react-router-dom";
33
import { Formik, Form, Field, FieldProps } from "formik";
44
import debounce from "lodash/debounce";
55
import { useTranslation } from "react-i18next";
6-
76
import { Notification } from "@stellar/design-system";
7+
import { useSelector } from "react-redux";
88

99
import { FormRows } from "popup/basics/Forms";
1010
import { ROUTES } from "popup/constants/routes";
@@ -13,17 +13,19 @@ import { isMainnet, isTestnet } from "helpers/stellar";
1313
import { SubviewHeader } from "popup/components/SubviewHeader";
1414
import { View } from "popup/basics/layout/View";
1515

16-
import { ManageAssetRows } from "../ManageAssetRows";
17-
import { SearchInput, SearchCopy, SearchResults } from "../AssetResults";
18-
import { useAssetLookup } from "./hooks/useAssetLookup";
19-
import { useGetSearchData } from "./hooks/useSearchData";
2016
import { NetworkDetails } from "@shared/constants/stellar";
2117
import { RequestState } from "helpers/hooks/fetchHookInterface";
2218
import { Loading } from "popup/components/Loading";
2319
import { openTab } from "popup/helpers/navigate";
2420
import { newTabHref } from "helpers/urls";
2521
import { AppDataType } from "helpers/hooks/useGetAppData";
2622
import { reRouteOnboarding } from "popup/helpers/route";
23+
import { balancesSelector } from "popup/ducks/cache";
24+
25+
import { ManageAssetRows } from "../ManageAssetRows";
26+
import { SearchInput, SearchCopy, SearchResults } from "../AssetResults";
27+
import { useAssetLookup } from "./hooks/useAssetLookup";
28+
import { useGetSearchData } from "./hooks/useSearchData";
2729

2830
import "./styles.scss";
2931

@@ -62,6 +64,7 @@ const ResultsHeader = () => {
6264
export const SearchAsset = () => {
6365
const { t } = useTranslation();
6466
const location = useLocation();
67+
const cachedBalances = useSelector(balancesSelector);
6568

6669
const ResultsRef = useRef<HTMLDivElement>(null);
6770

@@ -95,12 +98,13 @@ export const SearchAsset = () => {
9598
const handleSearch = handleSearchRef.current;
9699

97100
useEffect(() => {
101+
/* This effect is keyed off of changes to cachedBalances as this let's us update the UI when an asset is removed */
98102
const getData = async () => {
99103
await fetchData(true);
100104
};
101105

102106
getData();
103-
}, []);
107+
}, [cachedBalances]);
104108

105109
if (
106110
state.state === RequestState.IDLE ||

extension/src/popup/views/SignTransaction/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,16 @@ export const Trustline = ({ operations, icons }: TrustlineProps) => {
597597

598598
return (
599599
<div className="SignTransaction__TrustlineRow">
600-
<div className="SignTransaction__TrustlineRow__Asset">
600+
<div
601+
className="SignTransaction__TrustlineRow__Asset"
602+
data-testid="SignTransaction__TrustlineRow__Asset"
603+
>
601604
{renderTrustlineAsset(line)}
602605
</div>
603-
<div className="SignTransaction__TrustlineRow__Type">
606+
<div
607+
className="SignTransaction__TrustlineRow__Type"
608+
data-testid="SignTransaction__TrustlineRow__Type"
609+
>
604610
{isRemoveTrustline ? (
605611
<>
606612
<Icon.MinusCircle />

0 commit comments

Comments
 (0)