-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathwallet.ts
59 lines (49 loc) · 1.56 KB
/
wallet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 };