Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet/frontend): add temporary card service #1554

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions packages/wallet/frontend/src/lib/api/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import {
getError,
httpClient,
type ErrorResponse,
type SuccessResponse
} from '../httpClient'

// TODO: update interface - can be moved to shared folder as well
export interface IUserCard {
name: string
number: string
expiry: string
cvv: number
isFrozen: boolean
}

type GetDetailsResponse = SuccessResponse<IUserCard>
type GetDetailsResult = GetDetailsResponse | ErrorResponse

type TerminateCardResult = SuccessResponse<boolean> | ErrorResponse

type FreezeResult = SuccessResponse<boolean> | ErrorResponse

type UnfreezeResult = SuccessResponse<boolean> | ErrorResponse

type UpdateSpendingLimitResult = SuccessResponse | ErrorResponse

type ChangePinResult = SuccessResponse | ErrorResponse

interface UserCardService {
getDetails(cookies?: string): Promise<GetDetailsResult>
terminate(): Promise<TerminateCardResult>
freeze(): Promise<FreezeResult>
unfreeze(): Promise<UnfreezeResult>
updateSpendingLimit(): Promise<UpdateSpendingLimitResult>
changePin(): Promise<ChangePinResult>
}

const createCardService = (): UserCardService => ({
async getDetails(cookies) {
try {
const response = await httpClient
.get(`card`, {
headers: {
...(cookies ? { Cookie: cookies } : {})
}
})
.json<GetDetailsResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
},

async terminate() {
try {
const response = await httpClient
.post('card/terminate')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
},

async freeze() {
try {
const response = await httpClient
.post('card/freeze')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
},

async unfreeze() {
try {
const response = await httpClient
.post('card/unfreeze')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
},

async updateSpendingLimit() {
try {
const response = await httpClient
.post('card/update-spending-limit')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
},

async changePin() {
try {
const response = await httpClient
.post('card/change-pin')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
}
})

const mock = (): UserCardService => ({
async getDetails() {
return Promise.resolve({
success: true,
message: 'Mocked getDetails',
result: {
name: 'John Doe',
number: '4242 4242 4242 4242',
expiry: '01/27',
cvv: 321,
isFrozen: Math.random() > 0.5 ? true : false
}
})
},

async terminate() {
return Promise.resolve({
success: true,
message: 'Mocked terminate',
result: true
})
},

async freeze() {
return Promise.resolve({
success: true,
message: 'Mocked freeze',
result: true
})
},

async unfreeze() {
return Promise.resolve({
success: true,
message: 'Mocked unfreeze',
result: true
})
},

async updateSpendingLimit() {
try {
const response = await httpClient
.post('card/update-spending-limit')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
},

async changePin() {
try {
const response = await httpClient
.post('card/change-pin')
.json<SuccessResponse>()
return response
} catch (error) {
return getError(error, '[TODO] UPDATE ME!')
}
}
})

const cardService = createCardService()
const cardServiceMock = mock()
export { cardService, cardServiceMock }
1 change: 1 addition & 0 deletions packages/wallet/frontend/src/pages/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function CardContainer() {
</div>
)
}

const UserCardPage: NextPageWithLayout = () => {
return (
<>
Expand Down
Loading