Skip to content

Commit

Permalink
refactor: dtos
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 27, 2024
1 parent ebe8b56 commit de48cc6
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 138 deletions.
40 changes: 0 additions & 40 deletions libs/common/src/dto/configure-nostr-relays.dto.ts

This file was deleted.

61 changes: 0 additions & 61 deletions libs/common/src/dto/create-offramp-swap.dto.ts

This file was deleted.

12 changes: 0 additions & 12 deletions libs/common/src/dto/find-swap.dto.ts

This file was deleted.

11 changes: 3 additions & 8 deletions libs/common/src/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// swap
export * from './find-swap.dto';
export * from './list-swaps.dto';
export * from './create-onramp-swap.dto';
export * from './create-offramp-swap.dto';

export * from './swap.dto';
export * from './quote.dto';
// nostr
export * from './configure-nostr-relays.dto';
export * from './send-encrypted-nostr-dm.dto';
export * from './nostr.dto';
export * from './sms.dto';
export * from './shares.dto';
export * from './solowallet.dto';
15 changes: 0 additions & 15 deletions libs/common/src/dto/list-swaps.dto.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {
IsDefined,
ValidateNested,
IsOptional,
Matches,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { NostrDirectMessageRequest, NostrRecipient } from '../types';
import { ConfigureNostrRelaysRequest, NostrDirectMessageRequest, NostrRecipient, NostrRelay } from '../types';

class NostrRecipientDto implements NostrRecipient {
@IsOptional()
Expand Down Expand Up @@ -44,3 +45,32 @@ export class SendEncryptedNostrDmDto implements NostrDirectMessageRequest {
@ApiProperty()
retry: boolean;
}

class NostrRelayDto implements NostrRelay {
@IsNotEmpty()
@IsString()
@Matches(/^wss?:\/\/.+/, {
message: 'Socket must be a valid WebSocket URL (ws:// or wss://)',
})
@Type(() => String)
@ApiProperty()
socket: string;

@IsBoolean()
@Type(() => Boolean)
@ApiProperty()
read: boolean;

@IsBoolean()
@Type(() => Boolean)
@ApiProperty()
write: boolean;
}

export class ConfigureNostrRelaysDto implements ConfigureNostrRelaysRequest {
@IsDefined()
@ValidateNested({ each: true })
@Type(() => NostrRelayDto)
@ApiProperty({ type: [NostrRelayDto] })
relays: NostrRelayDto[];
}
2 changes: 1 addition & 1 deletion libs/common/src/dto/solowallet.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type } from 'class-transformer';
import { IsNotEmpty, IsString, ValidateNested } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { CreateOnrampSwapDto } from './create-onramp-swap.dto';
import { CreateOnrampSwapDto } from './swap.dto';
import { DepositFundsRequest } from '../types';

export class DepositFundsRequestDto implements DepositFundsRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
IsDefined,
IsEnum,
ValidateNested,
IsNumber,
Min,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
Expand All @@ -16,6 +18,10 @@ import {
Currency,
OnrampSwapTarget,
SupportedCurrencies,
FindSwapRequest,
OfframpSwapRequest,
OfframpSwapTarget,
PaginatedRequest,
} from '../types';
import { Bolt11InvoiceDto, MobileMoneyDto } from './payments.dto';
import { TransformToCurrency } from './transforms';
Expand Down Expand Up @@ -74,3 +80,64 @@ export class CreateOnrampSwapDto implements OnrampSwapRequest {
@ApiProperty({ type: OnrampSwapTargetDto })
target: OnrampSwapTargetDto;
}


class OfframpSwapTargetDto implements OfframpSwapTarget {
@IsEnum(Currency)
@TransformToCurrency()
@ApiProperty({ enum: SupportedCurrencies, enumName: 'SupportedCurrencyType' })
currency: Currency;

@IsDefined()
@ValidateNested()
@Type(() => MobileMoneyDto)
@ApiProperty({ type: MobileMoneyDto })
payout: MobileMoneyDto;
}

export class CreateOfframpSwapDto implements OfframpSwapRequest {
@IsOptional()
@ValidateNested()
@Type(() => QuoteDto)
@ApiProperty({ type: QuoteDto })
quote: QuoteDto;

@IsNotEmpty()
@IsString()
@Type(() => String)
@ApiProperty()
reference: string;

@IsNotEmpty()
@IsString()
@Validate(IsStringifiedNumberConstraint)
@Type(() => String)
@ApiProperty()
amountFiat: string;

@IsNotEmpty()
@ValidateNested()
@Type(() => OfframpSwapTargetDto)
@ApiProperty({ type: OfframpSwapTargetDto })
target: OfframpSwapTargetDto;
}

export class FindSwapDto implements FindSwapRequest {
@IsNotEmpty()
@IsString()
@Type(() => String)
@ApiProperty()
id: string;
}

export class ListSwapsDto implements PaginatedRequest {
@ApiProperty()
@IsNumber()
@Min(0)
page: number;

@ApiProperty()
@IsNumber()
@Min(1)
size: number;
}

0 comments on commit de48cc6

Please sign in to comment.