Skip to content

Commit

Permalink
Extend Confirmation View with an optional value field (#1851)
Browse files Browse the repository at this point in the history
- Adds `value` optional parameter to `TransactionDataDto`.
- Adds `value` field to the `NativeStakingConfirmationView` entity.
- Adjusts tests accordingly.
  • Loading branch information
hectorgomezv authored Aug 26, 2024
1 parent 6f7ea68 commit b1233d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/routes/common/entities/transaction-data.dto.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { z } from 'zod';
import { HexSchema } from '@/validation/entities/schemas/hex.schema';
import { AddressSchema } from '@/validation/entities/schemas/address.schema';
import { NumericStringSchema } from '@/validation/entities/schemas/numeric-string.schema';

export const TransactionDataDtoSchema = z.object({
data: HexSchema,
to: AddressSchema.optional(),
value: NumericStringSchema.optional(),
});

export class TransactionDataDto
Expand All @@ -15,9 +17,14 @@ export class TransactionDataDto
data: `0x${string}`;
@ApiPropertyOptional({ description: 'The target Ethereum address' })
to?: `0x${string}`;
@ApiPropertyOptional({
description: 'The wei amount being sent to a payable function',
})
value?: string;

constructor(data: `0x${string}`, to: `0x${string}`) {
constructor(data: `0x${string}`, to?: `0x${string}`, value?: string) {
this.data = data;
this.to = to;
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class NativeStakingDepositConfirmationView
@ApiProperty()
annualNrr: number;

@ApiProperty()
value: number;

constructor(args: {
method: string;
parameters: DataDecodedParameter[] | null;
Expand All @@ -54,6 +57,7 @@ export class NativeStakingDepositConfirmationView
fee: number;
monthlyNrr: number;
annualNrr: number;
value: number;
}) {
this.method = args.method;
this.parameters = args.parameters;
Expand All @@ -64,5 +68,6 @@ export class NativeStakingDepositConfirmationView
this.fee = args.fee;
this.monthlyNrr = args.monthlyNrr;
this.annualNrr = args.annualNrr;
this.value = args.value;
}
}
4 changes: 4 additions & 0 deletions src/routes/transactions/transactions-view.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ describe('TransactionsViewController tests', () => {
const data = encodeFunctionData({
abi: parseAbi(['function deposit() external payable']),
});
const value = faker.string.numeric();
networkService.get.mockImplementation(({ url }) => {
if (url === `${safeConfigUrl}/api/v1/chains/${chain.chainId}`) {
return Promise.resolve({ data: chain, status: 200 });
Expand Down Expand Up @@ -614,6 +615,7 @@ describe('TransactionsViewController tests', () => {
.send({
to: deployment.address,
data,
value,
})
.expect(200)
.expect({
Expand All @@ -633,6 +635,7 @@ describe('TransactionsViewController tests', () => {
annualNrr:
dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!),
value: Number(value),
});
});

Expand Down Expand Up @@ -721,6 +724,7 @@ describe('TransactionsViewController tests', () => {
annualNrr:
dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!),
value: 0, // defaults to 0 if not provided in the request
});
});

Expand Down
5 changes: 4 additions & 1 deletion src/routes/transactions/transactions-view.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ export class TransactionsViewService {
});
} else if (nativeStakingTransaction) {
return await this.getNativeStakingDepositConfirmationView({
...nativeStakingTransaction,
chainId: args.chainId,
dataDecoded,
...nativeStakingTransaction,
value: args.transactionDataDto.value,
});
} else {
// Should not reach here
Expand Down Expand Up @@ -277,6 +278,7 @@ export class TransactionsViewService {
to: `0x${string}`;
data: `0x${string}`;
dataDecoded: DataDecoded;
value?: string;
}): Promise<NativeStakingDepositConfirmationView> {
const depositInfo = await this.nativeStakingMapper.mapDepositInfo({
chainId: args.chainId,
Expand All @@ -287,6 +289,7 @@ export class TransactionsViewService {
return new NativeStakingDepositConfirmationView({
method: args.dataDecoded.method,
parameters: args.dataDecoded.parameters,
value: args.value ? Number(args.value) : 0,
...depositInfo,
});
}
Expand Down

0 comments on commit b1233d3

Please sign in to comment.