Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(profiles): only sync wallets of available networks #13

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 3 additions & 7 deletions packages/profiles/source/notification.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ describeWithContext(
.reply(200, loader.json("test/fixtures/client/syncing.json"))
.get("/api/peers")
.reply(200, loader.json("test/fixtures/client/peers.json"))
.post("/api/wallets/search", {})
.query({ limit: 1 })
.reply(404, {
error: "RequestException",
message: "HTTP request returned status code 404",
statusCode: 404,
})
.get("/api/wallets", {})
.query({ limit: 1, nonce: 0 })
.reply(200, {})
.get("/api/wallets/D6i8P5N44rFto6M6RALyUXLLs7Q1A1WREW")
.reply(200, loader.json("test/fixtures/client/wallet.json"))
.get("/api/transactions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ describeWithContext(
.reply(200, loader.json("test/fixtures/client/peers.json"))
.get("/api/node/syncing")
.reply(200, loader.json("test/fixtures/client/syncing.json"))
.post("/api/wallets/search", {})
.query({ limit: 1 })
.reply(404, {
error: "RequestException",
message: "HTTP request returned status code 404",
statusCode: 404,
})
.get("/api/wallets", {})
.query({ limit: 1, nonce: 0 })
.reply(200, {})
.get("/api/wallets/D6i8P5N44rFto6M6RALyUXLLs7Q1A1WREW")
.reply(200, loader.json("test/fixtures/client/wallet.json"))
.persist();
Expand Down
10 changes: 3 additions & 7 deletions packages/profiles/source/transaction-index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ describe("TransactionIndex", ({ beforeAll, beforeEach, nock, assert, it, loader
.get("/api/node/syncing")
.reply(200, loader.json("test/fixtures/client/syncing.json"))

.post("/api/wallets/search", {})
.query({ limit: 1 })
.reply(404, {
error: "RequestException",
message: "HTTP request returned status code 404",
statusCode: 404,
})
.get("/api/wallets", {})
.query({ limit: 1, nonce: 0 })
.reply(200, {})

// default wallet
.get("/api/wallets/D6i8P5N44rFto6M6RALyUXLLs7Q1A1WREW")
Expand Down
10 changes: 3 additions & 7 deletions packages/profiles/source/transaction.aggregate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ describe("TransactionAggregate", ({ each, loader, afterEach, beforeAll, beforeEa
.reply(200, loader.json("test/fixtures/client/peers.json"))
.get("/api/node/syncing")
.reply(200, loader.json("test/fixtures/client/syncing.json"))
.post("/api/wallets/search", {})
.query({ limit: 1 })
.reply(404, {
error: "RequestException",
message: "HTTP request returned status code 404",
statusCode: 404,
})
.get("/api/wallets", {})
.query({ limit: 1, nonce: 0 })
.reply(200, {})
.get("/api/wallets/D6i8P5N44rFto6M6RALyUXLLs7Q1A1WREW")
.reply(200, loader.json("test/fixtures/client/wallet.json"))
.persist();
Expand Down
8 changes: 6 additions & 2 deletions packages/profiles/source/wallet.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Identifiers } from "./container.models";
import { ProfileRepository } from "./profile.repository";
import { WalletService } from "./wallet.service.js";

describe("WalletService", ({ afterEach, beforeAll, beforeEach, loader, nock, assert, stub, it }) => {
describe("WalletService", ({ beforeAll, beforeEach, loader, nock, assert, stub, it }) => {
beforeAll(() => bootContainer());

beforeEach(async (context) => {
Expand Down Expand Up @@ -72,8 +72,12 @@ describe("WalletService", ({ afterEach, beforeAll, beforeEach, loader, nock, ass

context.profile = await profileRepository.create("John Doe");

context.profile.coins().set("ARK", "ark.devnet");

context.wallet = await importByMnemonic(context.profile, identity.mnemonic, "ARK", "ark.devnet");

context.networkSpy = stub(context.profile, "availableNetworks").returnValue([context.wallet.network()]);

context.liveSpy = stub(context.wallet.network(), "isLive").returnValue(true);
context.testSpy = stub(context.wallet.network(), "isTest").returnValue(false);

Expand All @@ -87,7 +91,7 @@ describe("WalletService", ({ afterEach, beforeAll, beforeEach, loader, nock, ass

assert.not.throws(() => context.wallet.voting().current(), /has not been synced/);

stub(context.profile.wallets(), "values").returnValue([undefined]);
stub(context.profile.wallets(), "values").returnValue([]);
await context.subject.syncByProfile(context.profile);
});
});
9 changes: 8 additions & 1 deletion packages/profiles/source/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import { pqueueSettled } from "./helpers/queue.js";
export class WalletService implements IWalletService {
/** {@inheritDoc IWalletService.syncByProfile} */
public async syncByProfile(profile: IProfile): Promise<void> {
const availableNetworkIds = profile.availableNetworks().map((network) => network.id());

const wallets = profile
.wallets()
.values()
.filter((wallet) => availableNetworkIds.includes(wallet.networkId()));

const promises: (() => Promise<void>)[] = [];

for (const wallet of profile.wallets().values()) {
for (const wallet of wallets) {
promises.push(
() => wallet?.synchroniser().identity(),
() => wallet?.synchroniser().votes(),
Expand Down
10 changes: 3 additions & 7 deletions packages/profiles/source/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ describe("Wallet", ({ beforeAll, beforeEach, loader, nock, assert, stub, it }) =
.get("/api/node/syncing")
.reply(200, loader.json("test/fixtures/client/syncing.json"))

.post("/api/wallets/search", {})
.query({ limit: 1 })
.reply(404, {
error: "RequestException",
message: "HTTP request returned status code 404",
statusCode: 404,
})
.get("/api/wallets", {})
.query({ limit: 1, nonce: 0 })
.reply(200, {})

// default wallet
.get("/api/wallets/D6i8P5N44rFto6M6RALyUXLLs7Q1A1WREW")
Expand Down