Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
feat(profiles): implement RegistrationAggregate (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Aug 7, 2020
1 parent a7e45c8 commit 880cedc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/platform-sdk-ark/src/services/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class ClientService implements Contracts.ClientService {
}

private createSearchParams(body: Contracts.ClientPagination): { body: object; searchParams: object } {
const result = {
const result: any = {
body,
searchParams: {},
};
Expand All @@ -180,6 +180,28 @@ export class ClientService implements Contracts.ClientService {
}
}

if (result.body.entityType) {
result.body.type = 6;
result.body.typeGroup = 2;

result.body.asset = {
type: {
business: 0,
corePlugin: 3,
delegate: 4,
desktopWalletPlugin: 3,
}[result.body.entityType],
subType: {
business: 0,
corePlugin: 1,
delegate: 0,
desktopWalletPlugin: 2,
}[result.body.entityType],
};

delete result.body.entityType;
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Coins, Contracts } from "@arkecosystem/platform-sdk";

export class RegistrationAggregate {
// @TODO: add typehint
readonly #wallet;

// @TODO: add typehint
public constructor(wallet) {
this.#wallet = wallet;
}

public async businesses(query: Contracts.ClientPagination = {}): Promise<Coins.TransactionDataCollection> {
return this.#wallet.client().transactions({
...query,
entityType: "business",
senderPublicKey: this.#wallet.publicKey(),
});
}

public async delegates(query: Contracts.ClientPagination = {}): Promise<Coins.TransactionDataCollection> {
return this.#wallet.client().transactions({
...query,
entityType: "delegate",
senderPublicKey: this.#wallet.publicKey(),
});
}

public async corePlugins(query: Contracts.ClientPagination = {}): Promise<Coins.TransactionDataCollection> {
return this.#wallet.client().transactions({
...query,
entityType: "corePlugin",
senderPublicKey: this.#wallet.publicKey(),
});
}

public async desktopWalletPlugins(
query: Contracts.ClientPagination = {},
): Promise<Coins.TransactionDataCollection> {
return this.#wallet.client().transactions({
...query,
entityType: "desktopWalletPlugin",
senderPublicKey: this.#wallet.publicKey(),
});
}
}
9 changes: 9 additions & 0 deletions packages/platform-sdk-profiles/src/wallets/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DelegateMapper } from "./mappers/delegate-mapper";
import { ReadOnlyWallet } from "./read-only-wallet";
import { TransactionService } from "./wallet-transaction-service";
import { WalletData, WalletFlag, WalletSetting, WalletStruct } from "./wallet.models";
import { RegistrationAggregate } from "../profiles/aggregates/registration-aggregate";

export class Wallet {
#dataRepository!: DataRepository;
Expand Down Expand Up @@ -341,6 +342,14 @@ export class Wallet {
return this.#coin.client().syncing();
}

/**
* These methods serve as helpers to aggregate commonly used data.
*/

public registrationAggregate(): RegistrationAggregate {
return new RegistrationAggregate(this);
}

/**
* These methods serve as helpers to map wallet identifiers to various
* wallet instances that expose information like an avatar or balances.
Expand Down

0 comments on commit 880cedc

Please sign in to comment.