Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
chore: update Platform SDK dependencies (#3612)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored Apr 13, 2021
1 parent 848b2e1 commit df7c871
Show file tree
Hide file tree
Showing 26 changed files with 8,969 additions and 2,599 deletions.
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@
"testRunner": "jest-circus/runner"
},
"dependencies": {
"@arkecosystem/platform-sdk": "^4.1.10",
"@arkecosystem/platform-sdk-ada": "^4.1.10",
"@arkecosystem/platform-sdk-ark": "^4.1.10",
"@arkecosystem/platform-sdk-atom": "^4.1.10",
"@arkecosystem/platform-sdk-btc": "^4.1.10",
"@arkecosystem/platform-sdk-crypto": "^4.1.10",
"@arkecosystem/platform-sdk-egld": "^4.1.10",
"@arkecosystem/platform-sdk-eos": "^4.1.10",
"@arkecosystem/platform-sdk-eth": "^4.1.10",
"@arkecosystem/platform-sdk-intl": "^4.1.10",
"@arkecosystem/platform-sdk-lsk": "^4.1.10",
"@arkecosystem/platform-sdk-neo": "^4.1.10",
"@arkecosystem/platform-sdk-news": "^4.1.10",
"@arkecosystem/platform-sdk-profiles": "^4.1.10",
"@arkecosystem/platform-sdk-support": "^4.1.10",
"@arkecosystem/platform-sdk-trx": "^4.1.10",
"@arkecosystem/platform-sdk-xrp": "^4.1.10",
"@arkecosystem/platform-sdk": "^4.2.9",
"@arkecosystem/platform-sdk-ada": "^4.2.9",
"@arkecosystem/platform-sdk-ark": "^4.2.9",
"@arkecosystem/platform-sdk-atom": "^4.2.9",
"@arkecosystem/platform-sdk-btc": "^4.2.9",
"@arkecosystem/platform-sdk-crypto": "^4.2.9",
"@arkecosystem/platform-sdk-egld": "^4.2.9",
"@arkecosystem/platform-sdk-eos": "^4.2.9",
"@arkecosystem/platform-sdk-eth": "^4.2.9",
"@arkecosystem/platform-sdk-intl": "^4.2.9",
"@arkecosystem/platform-sdk-lsk": "^4.2.9",
"@arkecosystem/platform-sdk-neo": "^4.2.9",
"@arkecosystem/platform-sdk-news": "^4.2.9",
"@arkecosystem/platform-sdk-profiles": "^4.2.9",
"@arkecosystem/platform-sdk-support": "^4.2.9",
"@arkecosystem/platform-sdk-trx": "^4.2.9",
"@arkecosystem/platform-sdk-xrp": "^4.2.9",
"@arkecosystem/utils": "^1.3.0",
"@ledgerhq/hw-transport-node-hid-singleton": "^5.46.0",
"@sentry/react": "^6.2.3",
Expand Down
30 changes: 30 additions & 0 deletions src/app/hooks/use-profile-utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,34 @@ describe("useProfileUtils", () => {
expect(current.saveProfile(passwordProtectedProfile)).toEqual(undefined);
passwordInMemoryMock.mockRestore();
});

it("#getErroredNetworks", async () => {
const profile = env.profiles().findById(getDefaultProfileId());

const wrapper = ({ children }: any) => <ConfigurationProvider>{children}</ConfigurationProvider>;

const {
result: { current },
} = renderHook(() => useProfileUtils(env), { wrapper });

expect(current.getErroredNetworks(profile).hasErroredNetworks).toEqual(false);
expect(current.getErroredNetworks(profile).erroredNetworks).toHaveLength(0);
});

it("should have errored networks", async () => {
const profile = env.profiles().findById(getDefaultProfileId());
const walletRestoreMock = jest
.spyOn(profile.wallets().first(), "hasBeenPartiallyRestored")
.mockReturnValue(true);

const wrapper = ({ children }: any) => <ConfigurationProvider>{children}</ConfigurationProvider>;

const {
result: { current },
} = renderHook(() => useProfileUtils(env), { wrapper });

expect(current.getErroredNetworks(profile).hasErroredNetworks).toEqual(true);
expect(current.getErroredNetworks(profile).erroredNetworks).toHaveLength(1);
walletRestoreMock.mockRestore();
});
});
21 changes: 15 additions & 6 deletions src/app/hooks/use-profile-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Contracts, Environment, Helpers } from "@arkecosystem/platform-sdk-profiles";
import { uniq } from "@arkecosystem/utils";
import { useCallback, useMemo } from "react";
import { matchPath } from "react-router-dom";

Expand Down Expand Up @@ -59,10 +60,18 @@ export const useProfileUtils = (env: Environment) => {
[getProfileStoredPassword],
);

return useMemo(() => ({ getProfileById, getProfileFromUrl, getProfileStoredPassword, saveProfile }), [
getProfileFromUrl,
getProfileById,
saveProfile,
getProfileStoredPassword,
]);
const getErroredNetworks = useCallback((profile: Contracts.IProfile) => {
const erroredNetworks = profile
.wallets()
.values()
.filter((wallet) => wallet.hasBeenPartiallyRestored())
.map((wallet) => `${wallet.network().name()}`);

return { hasErroredNetworks: erroredNetworks.length > 0, erroredNetworks: uniq(erroredNetworks) };
}, []);

return useMemo(
() => ({ getProfileById, getProfileFromUrl, getProfileStoredPassword, saveProfile, getErroredNetworks }),
[getProfileFromUrl, getProfileById, saveProfile, getProfileStoredPassword, getErroredNetworks],
);
};
1 change: 1 addition & 0 deletions src/app/i18n/common/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const translations: { [key: string]: any } = {
ERROR: "Error",
ERRORS: {
INVALID_URL: "The link could not be opened: '{{url}}' is not a valid URL",
NETWORK_ERROR: "Failed to connect to {{network}}. Please check your peer settings",
},
EXCHANGE: "Exchange",
EXPLORER: "Explorer",
Expand Down
51 changes: 51 additions & 0 deletions src/domains/dashboard/pages/Dashboard/Dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Transport, { Observer } from "@ledgerhq/hw-transport";
import { createTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
import { LedgerProvider } from "app/contexts/Ledger/Ledger";
import * as useRandomNumberHook from "app/hooks/use-random-number";
import { toasts } from "app/services";
import { translations as dashboardTranslations } from "domains/dashboard/i18n";
import { translations as walletTranslations } from "domains/wallet/i18n";
import { createMemoryHistory } from "history";
Expand Down Expand Up @@ -192,4 +193,54 @@ describe("Dashboard", () => {
expect(history.location.pathname).toEqual(`/profiles/${fixtureProfileId}/wallets/import`);
expect(asFragment()).toMatchSnapshot();
});

it("should show warning for errored networks", async () => {
const walletRestoreMock = jest
.spyOn(profile.wallets().first(), "hasBeenPartiallyRestored")
.mockReturnValue(true);

const warningMock = jest.fn();
const toastSpy = jest.spyOn(toasts, "warning").mockImplementation(warningMock);

const { asFragment, getByTestId } = renderWithRouter(
<Route path="/profiles/:profileId/dashboard">
<Dashboard />
</Route>,
{
routes: [dashboardURL],
history,
withProfileSynchronizer: true,
},
);

await waitFor(
() => expect(within(getByTestId("TransactionTable")).getAllByTestId("TableRow")).toHaveLength(4),
{ timeout: 4000 },
);

expect(toastSpy).toHaveBeenCalled();

expect(asFragment()).toMatchSnapshot();
walletRestoreMock.mockRestore();
toastSpy.mockRestore();
});

it("should render loading state when profile is syncing", async () => {
const { asFragment, getByTestId } = renderWithRouter(
<Route path="/profiles/:profileId/dashboard">
<Dashboard />
</Route>,
{
routes: [dashboardURL],
history,
},
);

await waitFor(
() => expect(within(getByTestId("TransactionTable")).getAllByTestId("TableRow")).toHaveLength(8),
{ timeout: 4000 },
);

expect(asFragment()).toMatchSnapshot();
});
});
22 changes: 19 additions & 3 deletions src/domains/dashboard/pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Contracts } from "@arkecosystem/platform-sdk-profiles";
import { Page, Section } from "app/components/Layout";
import { useConfiguration } from "app/contexts";
import { useActiveProfile } from "app/hooks";
import { useConfiguration, useEnvironmentContext } from "app/contexts";
import { useActiveProfile, useProfileUtils } from "app/hooks";
import { toasts } from "app/services";
import { Wallets } from "domains/dashboard/components/Wallets";
import { useWalletConfig } from "domains/dashboard/hooks";
import { Transactions } from "domains/transaction/components/Transactions";
import React, { useMemo } from "react";
import React, { useEffect, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";

Expand All @@ -15,6 +16,8 @@ export const Dashboard = () => {
const activeProfile = useActiveProfile();

const { profileIsSyncing } = useConfiguration();
const { env } = useEnvironmentContext();
const { getErroredNetworks } = useProfileUtils(env);

const { selectedWallets } = useWalletConfig({ profile: activeProfile });

Expand All @@ -24,6 +27,19 @@ export const Dashboard = () => {
[activeProfile],
);

useEffect(() => {
if (profileIsSyncing) {
return;
}

const { hasErroredNetworks, erroredNetworks } = getErroredNetworks(activeProfile);
if (!hasErroredNetworks) {
return;
}

toasts.warning(t("COMMON.ERRORS.NETWORK_ERROR", { network: erroredNetworks.join(", ") }));
}, [profileIsSyncing, activeProfile, t, getErroredNetworks]);

return (
<>
<Page profile={activeProfile} isBackDisabled={true}>
Expand Down
Loading

0 comments on commit df7c871

Please sign in to comment.