-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from Greenstand/feat/recent-activity-items
feat: add recent activity items
- Loading branch information
Showing
6 changed files
with
95 additions
and
1 deletion.
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
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,59 @@ | ||
import { faker } from "@faker-js/faker"; | ||
import { Wallet } from "../types/wallet"; | ||
|
||
async function getWalletsRecentActivity(userId: string): Promise<Wallet[]> { | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
|
||
return Array.from({ length: 4 }, () => { | ||
const status = getRandomStatus(); | ||
return { | ||
id: faker.string.uuid(), | ||
name: faker.internet.username(), | ||
balance: getRandomBalance(status), | ||
createdAt: faker.date.past(), | ||
logo: faker.image.url(), | ||
status, | ||
}; | ||
}); | ||
} | ||
|
||
const wallets = Array.from({ length: 10 }, () => { | ||
const status = getRandomStatus(); | ||
return { | ||
id: faker.string.uuid(), | ||
name: faker.internet.username(), | ||
balance: getRandomBalance(status), | ||
createdAt: faker.date.past(), | ||
logo: faker.image.url(), | ||
status, | ||
}; | ||
}); | ||
|
||
function getRandomStatus(): "Received" | "Pending" | "Sent" { | ||
const statuses: ("Received" | "Pending" | "Sent")[] = [ | ||
"Received", | ||
"Pending", | ||
"Sent", | ||
]; | ||
return statuses[Math.floor(Math.random() * statuses.length)]; | ||
} | ||
|
||
function getRandomBalance(status: "Received" | "Pending" | "Sent"): string { | ||
const balance = faker.number.int({ min: 100, max: 300 }); | ||
|
||
if (status === "Pending") { | ||
return `${balance}`; | ||
} | ||
|
||
return status === "Sent" ? `-${balance}` : `+${balance}`; | ||
} | ||
|
||
async function getWalletByKeyword(keyword: string): Promise<Wallet[]> { | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
|
||
return wallets.filter(option => | ||
option.name.toLowerCase().includes(keyword.toLowerCase()), | ||
); | ||
} | ||
|
||
export { getWalletsRecentActivity, getWalletByKeyword }; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./useSession"; | ||
export * from "./logout"; | ||
// export * from "./logout"; | ||
export * from "./wallet"; |
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,20 @@ | ||
import { useEffect, useState } from "react"; | ||
import * as wallets from "../api/wallet"; | ||
import { Wallet } from "../types/wallet"; | ||
|
||
export default function useWalletList(userId: string | undefined) { | ||
const [list, setList] = useState<Wallet[]>([]); | ||
const [isWalletLoading, setIsWalletLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
async function load() { | ||
setIsWalletLoading(true); | ||
const ws = await wallets.getWalletsRecentActivity(userId || ""); | ||
setIsWalletLoading(false); | ||
setList(ws); | ||
} | ||
load(); | ||
}, []); | ||
|
||
return { list, isWalletLoading }; | ||
} |
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,8 @@ | ||
export type Wallet = { | ||
id: string; | ||
name: string; | ||
logo: string; | ||
balance: number; | ||
createdAt: Date; | ||
status: string; | ||
}; |
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