Skip to content

Commit

Permalink
Add numValidators to Native Staking confirmation view (#1868)
Browse files Browse the repository at this point in the history
Adds `numValidators` field to the Native Staking transaction confirmation view.
  • Loading branch information
hectorgomezv authored Aug 28, 2024
1 parent ca09d19 commit 0cde218
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class NativeStakingDepositConfirmationView
@ApiProperty()
value: number;

@ApiProperty()
numValidators: number;

@ApiProperty()
expectedAnnualReward: number;

Expand All @@ -74,6 +77,7 @@ export class NativeStakingDepositConfirmationView
monthlyNrr: number;
annualNrr: number;
value: number;
numValidators: number;
expectedAnnualReward: number;
expectedMonthlyReward: number;
expectedFiatAnnualReward: number;
Expand All @@ -90,6 +94,7 @@ export class NativeStakingDepositConfirmationView
this.monthlyNrr = args.monthlyNrr;
this.annualNrr = args.annualNrr;
this.value = args.value;
this.numValidators = args.numValidators;
this.expectedAnnualReward = args.expectedAnnualReward;
this.expectedMonthlyReward = args.expectedMonthlyReward;
this.expectedFiatAnnualReward = args.expectedFiatAnnualReward;
Expand Down
5 changes: 4 additions & 1 deletion src/routes/transactions/transactions-view.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { dedicatedStakingStatsBuilder } from '@/datasources/staking-api/entities
import { deploymentBuilder } from '@/datasources/staking-api/entities/__tests__/deployment.entity.builder';
import { networkStatsBuilder } from '@/datasources/staking-api/entities/__tests__/network-stats.entity.builder';
import { chainBuilder } from '@/domain/chains/entities/__tests__/chain.builder';
import { getNumberString } from '@/domain/common/utils/utils';
import {
multiSendEncoder,
multiSendTransactionsEncoder,
Expand Down Expand Up @@ -581,7 +582,7 @@ describe('TransactionsViewController tests', () => {
const data = encodeFunctionData({
abi: parseAbi(['function deposit() external payable']),
});
const value = faker.string.numeric({ length: 18 });
const value = getNumberString(64 * 10 ** 18 + 1);
const fiatPrice = 1212.23; // TODO: randomize
const nativeCoinPriceProviderResponse = {
[chain.pricesProvider.nativeCoin!]: {
Expand Down Expand Up @@ -657,6 +658,7 @@ describe('TransactionsViewController tests', () => {
monthlyNrr,
annualNrr,
value: Number(value),
numValidators: 2,
expectedAnnualReward,
expectedMonthlyReward,
expectedFiatAnnualReward,
Expand Down Expand Up @@ -758,6 +760,7 @@ describe('TransactionsViewController tests', () => {
dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!),
value: 0, // defaults to 0 if not provided in the request
numValidators: 0, // 0 as value is 0
expectedMonthlyReward: 0, // 0 as value is 0
expectedAnnualReward: 0, // 0 as value is 0
expectedFiatMonthlyReward: 0, // 0 as value is 0
Expand Down
7 changes: 7 additions & 0 deletions src/routes/transactions/transactions-view.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Inject, Injectable } from '@nestjs/common';

@Injectable({})
export class TransactionsViewService {
private static readonly ETH_ETHERS_PER_VALIDATOR = 32;
private readonly isNativeStakingEnabled: boolean;

constructor(
Expand Down Expand Up @@ -294,6 +295,11 @@ export class TransactionsViewService {
});
const value = args.value ? Number(args.value) : 0;
const chain = await this.chainsRepository.getChain(args.chainId);
const numValidators = Math.floor(
value /
Math.pow(10, chain.nativeCurrency.decimals) /
TransactionsViewService.ETH_ETHERS_PER_VALIDATOR,
);
const nativeCoinPrice =
await this.balancesRepository.getNativeCoinPrice(chain);

Expand All @@ -308,6 +314,7 @@ export class TransactionsViewService {
method: args.dataDecoded.method,
parameters: args.dataDecoded.parameters,
value,
numValidators,
expectedAnnualReward,
expectedMonthlyReward,
expectedFiatAnnualReward,
Expand Down

0 comments on commit 0cde218

Please sign in to comment.