|
| 1 | +import { faker } from "@faker-js/faker"; |
| 2 | +import { Wallet } from "../types/wallet"; |
| 3 | + |
| 4 | +async function getWalletsRecentActivity(userId: string): Promise<Wallet[]> { |
| 5 | + await new Promise(resolve => setTimeout(resolve, 100)); |
| 6 | + |
| 7 | + return Array.from({ length: 4 }, () => { |
| 8 | + const status = getRandomStatus(); |
| 9 | + return { |
| 10 | + id: faker.string.uuid(), |
| 11 | + name: faker.internet.username(), |
| 12 | + balance: getRandomBalance(status), |
| 13 | + createdAt: faker.date.past(), |
| 14 | + logo: faker.image.url(), |
| 15 | + status, |
| 16 | + }; |
| 17 | + }); |
| 18 | +} |
| 19 | + |
| 20 | +const wallets = Array.from({ length: 10 }, () => { |
| 21 | + const status = getRandomStatus(); |
| 22 | + return { |
| 23 | + id: faker.string.uuid(), |
| 24 | + name: faker.internet.username(), |
| 25 | + balance: getRandomBalance(status), |
| 26 | + createdAt: faker.date.past(), |
| 27 | + logo: faker.image.url(), |
| 28 | + status, |
| 29 | + }; |
| 30 | +}); |
| 31 | + |
| 32 | +function getRandomStatus(): "Received" | "Pending" | "Sent" { |
| 33 | + const statuses: ("Received" | "Pending" | "Sent")[] = [ |
| 34 | + "Received", |
| 35 | + "Pending", |
| 36 | + "Sent", |
| 37 | + ]; |
| 38 | + return statuses[Math.floor(Math.random() * statuses.length)]; |
| 39 | +} |
| 40 | + |
| 41 | +function getRandomBalance(status: "Received" | "Pending" | "Sent"): string { |
| 42 | + const balance = faker.number.int({ min: 100, max: 300 }); |
| 43 | + |
| 44 | + if (status === "Pending") { |
| 45 | + return `${balance}`; |
| 46 | + } |
| 47 | + |
| 48 | + return status === "Sent" ? `-${balance}` : `+${balance}`; |
| 49 | +} |
| 50 | + |
| 51 | +async function getWalletByKeyword(keyword: string): Promise<Wallet[]> { |
| 52 | + await new Promise(resolve => setTimeout(resolve, 100)); |
| 53 | + |
| 54 | + return wallets.filter(option => |
| 55 | + option.name.toLowerCase().includes(keyword.toLowerCase()), |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +export { getWalletsRecentActivity, getWalletByKeyword }; |
0 commit comments