-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet/frontend): add temporary card service (#1554)
* Add initial cards api * Add card service mock * Format
- Loading branch information
1 parent
f80db89
commit bf9844a
Showing
2 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ function CardContainer() { | |
</div> | ||
) | ||
} | ||
|
||
const UserCardPage: NextPageWithLayout = () => { | ||
return ( | ||
<> | ||
|