Skip to content

Commit

Permalink
Add optional attributes to PolkadotTransaction (#271)
Browse files Browse the repository at this point in the history
* chore: add missing attributes for polkadot transactions

* chore: add changeset

* fix: remove bondExtra - case handled separately
  • Loading branch information
jdomingos authored Dec 7, 2023
1 parent a466649 commit 6a5771c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-dolls-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/wallet-api-core": minor
---

add optional attributes for PolkadotTransaction
12 changes: 12 additions & 0 deletions packages/core/src/families/polkadot/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ export const serializePolkadotTransaction = ({
mode,
fee,
era,
validators,
numOfSlashingSpans,
rewardDestination,
}: PolkadotTransaction): RawPolkadotTransaction => ({
amount: amount.toString(),
recipient,
family,
mode,
fee: fee ? fee.toString() : undefined,
era,
validators,
numOfSlashingSpans,
rewardDestination,
});

export const deserializePolkadotTransaction = ({
Expand All @@ -24,11 +30,17 @@ export const deserializePolkadotTransaction = ({
mode,
fee,
era,
validators,
numOfSlashingSpans,
rewardDestination,
}: RawPolkadotTransaction): PolkadotTransaction => ({
amount: new BigNumber(amount),
recipient,
family,
mode,
fee: fee ? new BigNumber(fee) : undefined,
era,
validators,
numOfSlashingSpans,
rewardDestination,
});
11 changes: 9 additions & 2 deletions packages/core/src/families/polkadot/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import type BigNumber from "bignumber.js";
import BigNumber from "bignumber.js";
import type { z } from "zod";
import type { TransactionCommon } from "../index";
import { TransactionCommon } from "../types";
import type {
schemaPolkadotOperationMode,
schemaPolkadotRewardDestination,
schemaRawPolkadotTransaction,
} from "./validation";

export type PolkadotOperationMode = z.infer<typeof schemaPolkadotOperationMode>;
export type PolkadotRewardDestination = z.infer<
typeof schemaPolkadotRewardDestination
>;

export type PolkadotTransaction = TransactionCommon & {
readonly family: RawPolkadotTransaction["family"];
mode: PolkadotOperationMode;
fee?: BigNumber;
era?: number;
validators?: string[];
numOfSlashingSpans?: number;
rewardDestination?: PolkadotRewardDestination;
};

export type RawPolkadotTransaction = z.infer<
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/families/polkadot/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ export const schemaPolkadotOperationMode = z.enum([
"claimReward",
]);

export const schemaPolkadotRewardDestination = z.enum([
"Staked",
"Stash",
"Controller",
"Account",
"None",
]);

export const schemaRawPolkadotTransaction = schemaTransactionCommon.extend({
family: z.literal(schemaFamilies.enum.polkadot),
mode: schemaPolkadotOperationMode,
fee: z.string().optional(),
era: z.number().optional(),
validators: z.array(z.string()).optional(),
rewardDestination: schemaPolkadotRewardDestination.optional(),
numOfSlashingSpans: z.number().optional(),
});

2 comments on commit 6a5771c

@vercel
Copy link

@vercel vercel bot commented on 6a5771c Dec 7, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wallet-api – ./apps/docs

wallet-api-git-main-ledgerhq.vercel.app
wallet.api.live.ledger.com
wallet-api-ledgerhq.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6a5771c Dec 7, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wallet-api-wallet-api-tools – ./apps/wallet-api-tools

wallet-api-wallet-api-tools.vercel.app
wallet-api-wallet-api-tools-ledgerhq.vercel.app
wallet-api-wallet-api-tools-git-main-ledgerhq.vercel.app

Please sign in to comment.