Skip to content

Commit f7e242d

Browse files
authored
feat: bring grant response type into shared package (#1377)
- Bring grant response type into shared package
1 parent 93ffac2 commit f7e242d

File tree

8 files changed

+84
-66
lines changed

8 files changed

+84
-66
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { NextFunction, Request } from 'express'
22
import { RafikiAuthService } from '@/rafiki/auth/service'
3-
import { GetGrantsQuery, Grant } from '@/rafiki/auth/generated/graphql'
3+
import { Grant } from '@/rafiki/auth/generated/graphql'
44
import { validate } from '@/shared/validate'
55
import { grantResponseSchema } from '@/grant/validation'
66
import { GrantService } from '@/grant/service'
77
import { Controller, toSuccessResponse } from '@shared/backend'
8+
import { GrantResponse, GrantsListResponse } from '@wallet/shared'
89

910
interface IGrantController {
1011
list: Controller<Grant[]>
@@ -22,7 +23,7 @@ export class GrantController implements IGrantController {
2223

2324
list = async (
2425
req: Request,
25-
res: CustomResponse<Grant[]>,
26+
res: CustomResponse<GrantResponse[]>,
2627
next: NextFunction
2728
) => {
2829
try {
@@ -35,7 +36,7 @@ export class GrantController implements IGrantController {
3536

3637
listWithPagination = async (
3738
req: Request,
38-
res: CustomResponse<GetGrantsQuery>,
39+
res: CustomResponse<GrantsListResponse>,
3940
next: NextFunction
4041
) => {
4142
try {
@@ -61,7 +62,7 @@ export class GrantController implements IGrantController {
6162

6263
getById = async (
6364
req: Request,
64-
res: CustomResponse<Grant>,
65+
res: CustomResponse<GrantResponse>,
6566
next: NextFunction
6667
) => {
6768
try {
@@ -75,7 +76,7 @@ export class GrantController implements IGrantController {
7576

7677
getByInteraction = async (
7778
req: Request,
78-
res: CustomResponse<Grant>,
79+
res: CustomResponse<GrantResponse>,
7980
next: NextFunction
8081
) => {
8182
try {
@@ -93,7 +94,7 @@ export class GrantController implements IGrantController {
9394

9495
setInteractionResponse = async (
9596
req: Request,
96-
res: CustomResponse<Grant>,
97+
res: CustomResponse<GrantResponse>,
9798
next: NextFunction
9899
) => {
99100
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Grant } from '@/lib/api/grants'
21
import { Badge, getStatusBadgeIntent } from '@/ui/Badge'
32
import { SimpleArrow } from './icons/Arrow'
3+
import { GrantResponse } from '@wallet/shared'
44

5-
type GrantDetailsProps = { grant: Grant }
5+
type GrantDetailsProps = { grant: GrantResponse }
66

77
export const GrantDetails = ({ grant }: GrantDetailsProps) => {
88
return (

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

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,11 @@ import {
55
type ErrorResponse,
66
type SuccessResponse
77
} from '../httpClient'
8-
9-
const GRANT_STATE = {
10-
APPROVED: 'APPROVED',
11-
FINALIZED: 'FINALIZED',
12-
PENDING: 'PENDING',
13-
PROCESSING: 'PROCESSING'
14-
} as const
15-
type GrantState = keyof typeof GRANT_STATE
16-
17-
const GRANT_FINALIZATION = {
18-
ISSUED: 'ISSUED',
19-
REJECTED: 'REJECTED',
20-
REVOKED: 'REVOKED'
21-
}
22-
type GrantFinalization = keyof typeof GRANT_FINALIZATION
23-
24-
type PaymentAmount = {
25-
value: string
26-
assetCode: string
27-
assetScale: number
28-
formattedAmount?: string
29-
}
30-
31-
type Access = {
32-
id: string
33-
identifier: string | null
34-
actions: string[]
35-
type: string
36-
limits: {
37-
receiver: string | null
38-
debitAmount: PaymentAmount | null
39-
receiveAmount: PaymentAmount | null
40-
interval: string | null
41-
} | null
42-
}
43-
44-
export type Grant = {
45-
id: string
46-
client: string
47-
state: GrantState
48-
createdAt: string
49-
access: Access[]
50-
finalizationReason?: GrantFinalization
51-
}
8+
import { GrantResponse } from '@wallet/shared'
529

5310
type GrantNode = {
5411
cursor: string
55-
node: Grant
12+
node: GrantResponse
5613
}
5714

5815
export type GrantsPageInfo = {
@@ -80,10 +37,10 @@ export type GrantListArgs = z.infer<typeof grantsListSchema>
8037
type GrantsListResult = SuccessResponse<GrantsList>
8138
type GrantsListResponse = GrantsListResult | ErrorResponse
8239

83-
type ListGrantsResult = SuccessResponse<Grant[]>
40+
type ListGrantsResult = SuccessResponse<GrantResponse[]>
8441
type ListGrantsResponse = ListGrantsResult | ErrorResponse
8542

86-
type GetGrantResult = SuccessResponse<Grant>
43+
type GetGrantResult = SuccessResponse<GrantResponse>
8744
type GetGrantResponse = GetGrantResult | ErrorResponse
8845
type DeleteGrantResponse = SuccessResponse | ErrorResponse
8946

packages/wallet/frontend/src/lib/hooks/useGrants.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { useHttpRequest } from './useHttp'
22
import { useCallback, useEffect, useState } from 'react'
3-
import {
4-
GrantListArgs,
5-
GrantsList,
6-
grantsListSchema,
7-
grantsService
8-
} from '../api/grants'
3+
import { GrantListArgs, grantsListSchema, grantsService } from '../api/grants'
94
import { GRANTS_DISPLAY_NR } from '@/utils/constants'
105
import { useTypedRouter } from './useTypedRouter'
6+
import { GrantsListResponse } from '@wallet/shared'
117

128
type GrantQueryParams = Record<keyof GrantListArgs, string | number>
139

@@ -27,7 +23,7 @@ export const useGrants = () => {
2723
const router = useTypedRouter(grantsListSchema)
2824
const { after, before, first, last } = router.query as GrantQueryParams
2925
const [request, loading, error] = useHttpRequest()
30-
const [grantsList, setGrantsList] = useState<GrantsList>(defaultState)
26+
const [grantsList, setGrantsList] = useState<GrantsListResponse>(defaultState)
3127

3228
const fetch = useCallback(
3329
async (pagination: Record<string, string | number>) => {

packages/wallet/frontend/src/pages/grant-interactions/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type {
44
} from 'next/types'
55
import { z } from 'zod'
66
import { formatAmount, replaceWalletAddressProtocol } from '@/utils/helpers'
7-
import { Grant, grantsService } from '@/lib/api/grants'
7+
import { grantsService } from '@/lib/api/grants'
88
import { Button } from '@/ui/Button'
99
import Image from 'next/image'
1010
import { useDialog } from '@/lib/hooks/useDialog'
1111
import { ErrorDialog } from '@/components/dialogs/ErrorDialog'
1212
import { useRouter } from 'next/router'
13+
import { GrantResponse } from '@wallet/shared'
1314

1415
type GrantInteractionPageProps = InferGetServerSidePropsType<
1516
typeof getServerSideProps
@@ -123,7 +124,7 @@ const querySchema = z.object({
123124
})
124125

125126
export const getServerSideProps: GetServerSideProps<{
126-
grant: Grant
127+
grant: GrantResponse
127128
interactionId: string
128129
nonce: string
129130
clientName: string

packages/wallet/frontend/src/pages/grants/[grantId].tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
formatDate,
1212
replaceWalletAddressProtocol
1313
} from '@/utils/helpers'
14-
import { Grant, grantsService } from '@/lib/api/grants'
14+
import { grantsService } from '@/lib/api/grants'
1515
import { Button } from '@/ui/Button'
1616
import { useDialog } from '@/lib/hooks/useDialog'
1717
import { ConfirmationDialog } from '@/components/dialogs/ConfirmationDialog'
@@ -20,6 +20,7 @@ import { ErrorDialog } from '@/components/dialogs/ErrorDialog'
2020
import { useRouter } from 'next/router'
2121
import Image from 'next/image'
2222
import { GrantDetails } from '@/components/GrantDetails'
23+
import { GrantResponse } from '@wallet/shared'
2324

2425
type GrantPageProps = InferGetServerSidePropsType<typeof getServerSideProps>
2526

@@ -86,7 +87,7 @@ const querySchema = z.object({
8687
})
8788

8889
export const getServerSideProps: GetServerSideProps<{
89-
grant: Grant
90+
grant: GrantResponse
9091
}> = async (ctx) => {
9192
const result = querySchema.safeParse(ctx.query)
9293

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const GRANT_STATE = {
2+
APPROVED: 'APPROVED',
3+
FINALIZED: 'FINALIZED',
4+
PENDING: 'PENDING',
5+
PROCESSING: 'PROCESSING'
6+
} as const
7+
type GrantState = keyof typeof GRANT_STATE
8+
9+
const GRANT_FINALIZATION = {
10+
ISSUED: 'ISSUED',
11+
REJECTED: 'REJECTED',
12+
REVOKED: 'REVOKED'
13+
}
14+
type GrantFinalization = keyof typeof GRANT_FINALIZATION
15+
16+
type PaymentAmount = {
17+
value: string
18+
assetCode: string
19+
assetScale: number
20+
formattedAmount?: string
21+
}
22+
23+
type Access = {
24+
id: string
25+
identifier: string | null
26+
actions: string[]
27+
type: string
28+
limits: {
29+
receiver: string | null
30+
debitAmount: PaymentAmount | null
31+
receiveAmount: PaymentAmount | null
32+
interval: string | null
33+
} | null
34+
}
35+
36+
export interface GrantResponse {
37+
id: string
38+
client: string
39+
state: GrantState
40+
createdAt: string
41+
access: Access[]
42+
finalizationReason?: GrantFinalization
43+
}
44+
45+
type GrantNode = {
46+
cursor: string
47+
node: GrantResponse
48+
}
49+
50+
type GrantsPageInfo = {
51+
endCursor: string
52+
startCursor: string
53+
hasNextPage: boolean
54+
hasPreviousPage: boolean
55+
}
56+
export interface GrantsListResponse {
57+
grants: {
58+
edges: GrantNode[]
59+
pageInfo: GrantsPageInfo
60+
}
61+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './account'
22
export * from './asset'
33
export * from './rate'
4+
export * from './grant'

0 commit comments

Comments
 (0)