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

feat: sync wallet data #2748

Merged
merged 29 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e8da4ca
feat: add scheduler service
clucasalcantara Aug 28, 2020
327e7ba
fix: fix types
clucasalcantara Aug 28, 2020
20f0f60
feat: apply sync on initialize, run scheduler
clucasalcantara Aug 28, 2020
b3218ba
refactor: remove other calls for sync due to initialization and sched…
clucasalcantara Aug 28, 2020
abd0752
wip
Aug 29, 2020
8c0b863
style: resolve style guide violations
faustbrian Aug 29, 2020
6dcd373
Merge branch '3.0-react' into feat/sync-wallet-data
Aug 29, 2020
1fefb17
Merge branch '3.0-react' into feat/sync-wallet-data
faustbrian Aug 29, 2020
a6b54b5
Merge branch '3.0-react' into feat/sync-wallet-data
clucasalcantara Aug 30, 2020
b689f53
Merge branch '3.0-react' into feat/sync-wallet-data
faustbrian Aug 31, 2020
eba6f19
chore: add nock for crypto compare
clucasalcantara Aug 31, 2020
67be21b
Merge branch '3.0-react' into feat/sync-wallet-data
faustbrian Aug 31, 2020
841d20a
Merge branch '3.0-react' into feat/sync-wallet-data
Aug 31, 2020
3e5156b
wip
Aug 31, 2020
275679c
tests: update snapshots
clucasalcantara Aug 31, 2020
1f8b02c
tests: wip fix address tests
clucasalcantara Aug 31, 2020
7ccf4cb
fix: duplicatated import
clucasalcantara Aug 31, 2020
b26407b
tests: update snapshots
clucasalcantara Sep 1, 2020
e42e893
Merge branch '3.0-react' into feat/sync-wallet-data
Sep 1, 2020
ffcfcba
wip
Sep 1, 2020
2d1afa0
style: resolve style guide violations
faustbrian Sep 1, 2020
6d344ef
Merge branch '3.0-react' into feat/sync-wallet-data
faustbrian Sep 1, 2020
0e1ee21
tests: ignore temp console error in tests
clucasalcantara Sep 1, 2020
103799a
tests: update tests and increse coverage
clucasalcantara Sep 1, 2020
607e189
feat: add echange ratwes sync
clucasalcantara Sep 1, 2020
51feaad
chore: use promise all settled
clucasalcantara Sep 1, 2020
289527c
chore: rename sync function for wallets data
clucasalcantara Sep 1, 2020
5a74b10
wip
Sep 1, 2020
0756d25
Merge branch '3.0-react' into feat/sync-wallet-data
Sep 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@
"testRunner": "jest-circus/runner"
},
"dependencies": {
"@arkecosystem/platform-sdk": "^0.9.327",
"@arkecosystem/platform-sdk-ada": "^0.9.327",
"@arkecosystem/platform-sdk-ark": "^0.9.327",
"@arkecosystem/platform-sdk-atom": "^0.9.327",
"@arkecosystem/platform-sdk-btc": "^0.9.327",
"@arkecosystem/platform-sdk-crypto": "^0.9.327",
"@arkecosystem/platform-sdk-eos": "^0.9.327",
"@arkecosystem/platform-sdk-eth": "^0.9.327",
"@arkecosystem/platform-sdk-intl": "^0.9.327",
"@arkecosystem/platform-sdk-lsk": "^0.9.327",
"@arkecosystem/platform-sdk-markets": "^0.9.327",
"@arkecosystem/platform-sdk-neo": "^0.9.327",
"@arkecosystem/platform-sdk-news": "^0.9.327",
"@arkecosystem/platform-sdk-profiles": "^0.9.327",
"@arkecosystem/platform-sdk-support": "^0.9.327",
"@arkecosystem/platform-sdk-trx": "^0.9.327",
"@arkecosystem/platform-sdk-xlm": "^0.9.327",
"@arkecosystem/platform-sdk-xmr": "^0.9.327",
"@arkecosystem/platform-sdk-xrp": "^0.9.327",
"@arkecosystem/platform-sdk": "^0.9.329",
"@arkecosystem/platform-sdk-ada": "^0.9.329",
"@arkecosystem/platform-sdk-ark": "^0.9.329",
"@arkecosystem/platform-sdk-atom": "^0.9.329",
"@arkecosystem/platform-sdk-btc": "^0.9.329",
"@arkecosystem/platform-sdk-crypto": "^0.9.329",
"@arkecosystem/platform-sdk-eos": "^0.9.329",
"@arkecosystem/platform-sdk-eth": "^0.9.329",
"@arkecosystem/platform-sdk-intl": "^0.9.329",
"@arkecosystem/platform-sdk-lsk": "^0.9.329",
"@arkecosystem/platform-sdk-markets": "^0.9.329",
"@arkecosystem/platform-sdk-neo": "^0.9.329",
"@arkecosystem/platform-sdk-news": "^0.9.329",
"@arkecosystem/platform-sdk-profiles": "^0.9.329",
"@arkecosystem/platform-sdk-support": "^0.9.329",
"@arkecosystem/platform-sdk-trx": "^0.9.329",
"@arkecosystem/platform-sdk-xlm": "^0.9.329",
"@arkecosystem/platform-sdk-xmr": "^0.9.329",
"@arkecosystem/platform-sdk-xrp": "^0.9.329",
"@arkecosystem/utils": "^1.2.0",
"@tippyjs/react": "^4.0.5",
"@types/react-linkify": "^1.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ exports[`Application root should render without crashing 1`] = `
"calls": Array [
Array [
<BrowserRouter>
<App />
<App
syncInterval={300000}
/>
</BrowserRouter>,
<div
id="root"
Expand Down
2 changes: 1 addition & 1 deletion src/app/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe("App", () => {
expect(getByTestId("Splash__text")).toBeInTheDocument();

await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
await new Promise((resolve) => setTimeout(resolve, 3000));
});

await waitFor(() => {
Expand Down
26 changes: 14 additions & 12 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { middlewares, RouterView, routes } from "../router";
import { EnvironmentProvider, useEnvironmentContext } from "./contexts";
import { useNetworkStatus } from "./hooks";
import { i18n } from "./i18n";
import { httpClient } from "./services";
import { httpClient, Scheduler } from "./services";

const __DEV__ = process.env.NODE_ENV !== "production";

Expand All @@ -44,23 +44,21 @@ const Main = ({ syncInterval }: Props) => {
}, [pathname]);

useLayoutEffect(() => {
const syncDelegates = async () => {
console.log("Running delegates sync...");

await env.delegates().sync("ARK", "devnet");

setShowSplash(false);
};
const syncDelegates = async () => env.delegates().syncAll();
const syncExchangeRates = async () => env.exchangeRates().syncAll();
const syncWallets = async () => env.wallets().syncAll();

const boot = async () => {
await env.verify(fixtureData);
await env.boot();
await syncDelegates();
await syncWallets();
await syncExchangeRates();
await persist();

console.info("Scheduling next delegates synchronization...");
setInterval(() => syncDelegates(), syncInterval);
Scheduler(syncInterval).schedule([syncDelegates, syncWallets, syncExchangeRates], persist);

await env.boot();
await persist();
setShowSplash(false);
};

if (process.env.REACT_APP_BUILD_MODE === "demo") {
Expand Down Expand Up @@ -128,3 +126,7 @@ export const App = ({ syncInterval }: Props) => {
</ErrorBoundary>
);
};

App.defaultProps = {
syncInterval: 300000,
};
11 changes: 7 additions & 4 deletions src/app/components/NavigationBar/NavigationBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createMemoryHistory } from "history";
import React from "react";
import { act } from "react-dom/test-utils";
import { Route } from "react-router-dom";
import { env, fireEvent, getDefaultProfileId, renderWithRouter } from "testing-library";
import { env, fireEvent, getDefaultProfileId, renderWithRouter, waitFor } from "testing-library";

import { NavigationBar } from "./NavigationBar";

Expand Down Expand Up @@ -140,7 +140,7 @@ describe("NavigationBar", () => {
});

it("should handle receive funds", async () => {
const { findByTestId, findAllByText, getAllByText, getByTestId, getByText } = renderWithRouter(
const { findByTestId, getAllByText, getByTestId, queryAllByTestId } = renderWithRouter(
<Route path="/profiles/:profileId/dashboard">
<NavigationBar profile={profile} />
</Route>,
Expand All @@ -160,15 +160,18 @@ describe("NavigationBar", () => {
fireEvent.click(getAllByText("Select")[0]);
});

expect(await findByTestId("modal__inner")).toHaveTextContent("Receive Funds");
await waitFor(() => expect(queryAllByTestId("ReceiveFunds__info")).toHaveLength(2));
await waitFor(() => expect(queryAllByTestId("ReceiveFunds__qrcode")).toHaveLength(1));

act(() => {
fireEvent.click(getByTestId("modal__close-btn"));
});

expect(() => getByTestId("modal__inner")).toThrow(/Unable to find an element by/);
});

it("should close the search wallet modal", async () => {
const { findByTestId, findByText, getByTestId } = renderWithRouter(
const { findByTestId, getByTestId } = renderWithRouter(
<Route path="/profiles/:profileId/dashboard">
<NavigationBar profile={profile} />
</Route>,
Expand Down
29 changes: 29 additions & 0 deletions src/app/services/Scheduler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Scheduler } from "./Scheduler";

describe("Scheduler test", () => {
jest.useFakeTimers();

it("should run an action after an determined interval", () => {
const action = jest.fn();
Scheduler(100).schedule([action]);
jest.advanceTimersByTime(100);
expect(action).toHaveBeenCalled();
});

it("should run an action using the default interval", () => {
const action = jest.fn();
Scheduler().schedule([action]);
jest.advanceTimersByTime(300000);
expect(action).toHaveBeenCalled();
});

it("should run actions and the done callback", () => {
const action = jest.fn();
const done = jest.fn();
Scheduler().schedule([action], done);

jest.advanceTimersByTime(300500);
expect(action).toHaveBeenCalled();
expect(done).toHaveBeenCalled();
});
});
12 changes: 12 additions & 0 deletions src/app/services/Scheduler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const Scheduler = (interval = 300000) => ({
Copy link
Contributor

@faustbrian faustbrian Aug 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions should always be camelCase and classes PascalClass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that we should create a class instead of just a function in this case to explicit that the Scheduler should be service/module ? 🤔

schedule: (actions: any, done: Function) => {
for (const action of actions) {
console.log(`Scheduling action ${action.name} for every ${interval / 60000} mins`);

setInterval(() => action(), interval);

// Run a done action once all timers runned
return done && setTimeout(() => done(), interval + 500);
}
},
});
2 changes: 2 additions & 0 deletions src/app/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HttpClient } from "./HttpClient";

export const httpClient = new HttpClient(10);

export * from "./Scheduler";
Loading