Skip to content

Commit 461523a

Browse files
authored
feat: bring incoming payment and quote response type into shared package (#1395)
* - Bring transfer response type into shared package * fix fetch wallet types
1 parent 4c52eee commit 461523a

16 files changed

Lines changed: 49 additions & 52 deletions

File tree

packages/wallet/backend/src/incomingPayment/controller.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ import {
66
} from '@/incomingPayment/validation'
77
import { IncomingPaymentService } from '@/incomingPayment/service'
88
import { Controller, toSuccessResponse } from '@shared/backend'
9-
10-
export interface PaymentDetails {
11-
value: number
12-
description?: string
13-
assetCode: string
14-
}
9+
import { PaymentDetailsResponse } from '@wallet/shared'
1510

1611
interface IIncomingPaymentController {
1712
create: Controller<{ url: string }>
18-
getPaymentDetailsByUrl: Controller<PaymentDetails>
13+
getPaymentDetailsByUrl: Controller<PaymentDetailsResponse>
1914
}
2015

2116
export class IncomingPaymentController implements IIncomingPaymentController {
@@ -47,7 +42,7 @@ export class IncomingPaymentController implements IIncomingPaymentController {
4742

4843
getPaymentDetailsByUrl = async (
4944
req: Request,
50-
res: CustomResponse<PaymentDetails>,
45+
res: CustomResponse<PaymentDetailsResponse>,
5146
next: NextFunction
5247
) => {
5348
try {

packages/wallet/backend/src/incomingPayment/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AccountService } from '@/account/service'
2-
import { PaymentDetails } from '@/incomingPayment/controller'
32
import { WalletAddress } from '@/walletAddress/model'
43
import { RafikiClient } from '@/rafiki/rafiki-client'
54
import { transformAmount } from '@/utils/helpers'
@@ -8,6 +7,7 @@ import { add, Duration } from 'date-fns'
87
import axios from 'axios'
98
import { Env } from '@/config/env'
109
import { NotFound } from '@shared/backend'
10+
import { PaymentDetailsResponse } from '@wallet/shared'
1111

1212
interface IIncomingPaymentService {
1313
create: (
@@ -16,7 +16,7 @@ interface IIncomingPaymentService {
1616
amount: number,
1717
description: string
1818
) => Promise<string>
19-
getPaymentDetailsByUrl: (url: string) => Promise<PaymentDetails>
19+
getPaymentDetailsByUrl: (url: string) => Promise<PaymentDetailsResponse>
2020
}
2121

2222
interface CreateReceiverParams {
@@ -93,7 +93,7 @@ export class IncomingPaymentService implements IIncomingPaymentService {
9393
return response.id
9494
}
9595

96-
async getPaymentDetailsByUrl(url: string): Promise<PaymentDetails> {
96+
async getPaymentDetailsByUrl(url: string): Promise<PaymentDetailsResponse> {
9797
const receiver = await this.rafikiClient.getReceiverById(url)
9898
const asset = {
9999
scale:

packages/wallet/backend/src/quote/controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { QuoteService } from './service'
55
import { quoteSchema } from './validation'
66
import { createExchangeQuoteSchema } from '@/account/validation'
77
import { Controller, toSuccessResponse } from '@shared/backend'
8+
import { QuoteResponse } from '@wallet/shared'
89

910
interface IQuoteController {
1011
create: Controller<Quote>
@@ -19,7 +20,7 @@ export class QuoteController implements IQuoteController {
1920

2021
create = async (
2122
req: Request,
22-
res: CustomResponse<QuoteWithFees | Quote>,
23+
res: CustomResponse<QuoteResponse>,
2324
next: NextFunction
2425
) => {
2526
try {
@@ -44,7 +45,7 @@ export class QuoteController implements IQuoteController {
4445

4546
createExchangeQuote = async (
4647
req: Request,
47-
res: CustomResponse<QuoteWithFees | Quote>,
48+
res: CustomResponse<QuoteResponse>,
4849
next: NextFunction
4950
) => {
5051
try {

packages/wallet/frontend/src/components/ExchangeRate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { getCurrencySymbol } from '@/utils/helpers'
22
import { memo } from 'react'
33
import { SimpleArrow } from './icons/Arrow'
4-
import { AssetOP, ExchangeRates } from '@/lib/api/asset'
4+
import { ExchangeRates } from '@/lib/api/asset'
5+
import { AssetOP } from '@wallet/shared'
56

67
type ExchangeRateProps = {
78
convertAmount: number

packages/wallet/frontend/src/components/dialogs/QuoteDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Quote } from '@/lib/api/transfers'
21
import { useOnboardingContext } from '@/lib/context/onboarding'
32
import { Button } from '@/ui/Button'
43
import { formatAmount, getFee } from '@/utils/helpers'
54
import { Dialog, Transition } from '@headlessui/react'
65
import { Fragment } from 'react'
76
import { PaperPlane } from '../icons/PaperPlane'
7+
import { QuoteResponse } from '@wallet/shared'
88

99
type QuoteDialogProps = {
1010
onClose: () => void
1111
onAccept: () => void
12-
quote: Quote
12+
quote: QuoteResponse
1313
type: string
1414
receiverName?: string
1515
}

packages/wallet/frontend/src/lib/api/account.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
type ErrorResponse,
66
type SuccessResponse
77
} from '../httpClient'
8-
import { acceptQuoteSchema, Quote } from './transfers'
8+
import { acceptQuoteSchema } from './transfers'
99
import {
1010
createAccountSchema,
1111
fundAccountSchema,
1212
withdrawFundsSchema,
1313
exchangeAssetSchema
1414
} from '@wallet/shared'
15+
import { QuoteResponse } from '@wallet/shared'
1516
import { WalletAddressResponse } from '@wallet/shared/src'
1617

1718
export type Account = {
@@ -44,7 +45,7 @@ type WithdrawFundsError = ErrorResponse<WithdrawFundsArgs | undefined>
4445
type WithdrawFundsResponse = SuccessResponse | WithdrawFundsError
4546

4647
type ExchangeArgs = z.infer<typeof exchangeAssetSchema>
47-
type QuoteResult = SuccessResponse<Quote>
48+
type QuoteResult = SuccessResponse<QuoteResponse>
4849
type ExchangeResponse = QuoteResult | ErrorResponse<ExchangeArgs | undefined>
4950

5051
type AcceptQuoteArgs = z.infer<typeof acceptQuoteSchema>

packages/wallet/frontend/src/lib/api/asset.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import {
66
} from '../httpClient'
77
import { AssetResponse, RatesResponse } from '@wallet/shared'
88

9-
export type AssetOP = {
10-
assetCode: string
11-
assetScale: number
12-
}
13-
149
export type ExchangeRates = Record<string, number>
1510

1611
type ListAssetsResult = SuccessResponse<AssetResponse[]>

packages/wallet/frontend/src/lib/api/transfers.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type ErrorResponse,
77
type SuccessResponse
88
} from '../httpClient'
9-
import { AssetOP } from '@/lib/api/asset'
9+
import { PaymentDetailsResponse, QuoteResponse } from '@wallet/shared'
1010

1111
export const sendSchema = z.object({
1212
walletAddressId: z
@@ -80,30 +80,13 @@ export const requestSchema = z
8080
}
8181
})
8282

83-
type PaymentDetails = {
84-
assetCode: string
85-
description?: string
86-
value: number
87-
}
88-
89-
type AmountProps = AssetOP & {
90-
value: string
91-
}
92-
9383
interface Expiration {
9484
value: number
9585
unit: string
9686
}
9787

98-
export interface Quote {
99-
id: string
100-
receiveAmount: AmountProps
101-
debitAmount: AmountProps
102-
fee?: AmountProps
103-
}
104-
10588
type SendArgs = z.infer<typeof sendSchema>
106-
type QuoteResult = SuccessResponse<Quote>
89+
type QuoteResult = SuccessResponse<QuoteResponse>
10790
type SendError = ErrorResponse<SendArgs | undefined>
10891
type SendResponse = QuoteResult | SendError
10992

@@ -116,7 +99,7 @@ type RequestResult = SuccessResponse<{ url: string }>
11699
type RequestError = ErrorResponse<RequestArgs | undefined>
117100
type RequestResponse = RequestResult | RequestError
118101

119-
type IncomingPaymentDetailsResult = SuccessResponse<PaymentDetails>
102+
type IncomingPaymentDetailsResult = SuccessResponse<PaymentDetailsResponse>
120103
type IncomingPaymentDetailsResponse =
121104
| IncomingPaymentDetailsResult
122105
| ErrorResponse

packages/wallet/frontend/src/lib/api/walletAddress.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
} from '../httpClient'
88
import {
99
ListWalletAddressesResponse,
10-
WalletAddressResponse
11-
} from '@wallet/shared/src'
12-
import { WalletAddressOP } from '@wallet/shared'
10+
WalletAddressResponse,
11+
WalletAddressOP
12+
} from '@wallet/shared'
1313

1414
export const createWalletAddressSchema = z.object({
1515
walletAddressName: z.string().toLowerCase().min(3, {

packages/wallet/frontend/src/pages/exchange.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
} from 'next/types'
1414
import { Account, accountService } from '@/lib/api/account'
1515
import { formatAmount, getCurrencySymbol, getObjectKeys } from '@/utils/helpers'
16-
import { AssetOP, assetService, ExchangeRates } from '@/lib/api/asset'
16+
import { assetService, ExchangeRates } from '@/lib/api/asset'
1717
import { Controller } from 'react-hook-form'
1818
import { NextPageWithLayout } from '@/lib/types/app'
1919
import { ErrorDialog } from '@/components/dialogs/ErrorDialog'
@@ -25,6 +25,7 @@ import { QuoteDialog } from '@/components/dialogs/QuoteDialog'
2525
import { balanceState } from '@/lib/balance'
2626
import { useSnapshot } from 'valtio'
2727
import { exchangeAssetSchema } from '@wallet/shared'
28+
import { AssetOP } from '@wallet/shared'
2829

2930
type ExchangeAssetProps = InferGetServerSidePropsType<typeof getServerSideProps>
3031
const ExchangeAssetPage: NextPageWithLayout<ExchangeAssetProps> = ({

0 commit comments

Comments
 (0)