Skip to content

Commit

Permalink
Merge pull request #381 from Greenstand/feat/recent-activity-items
Browse files Browse the repository at this point in the history
feat: add recent activity items
  • Loading branch information
pierrelstan authored Mar 3, 2025
2 parents 588e879 + 81a36fc commit a719c43
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"prettier": "^3.4.2"
},
"dependencies": {
"@faker-js/faker": "^9.5.1",
"dotenv": "^16.4.7",
"jotai": "^2.9.0",
"path": "^0.12.7",
Expand Down
59 changes: 59 additions & 0 deletions packages/core/src/api/wallet.ts
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 };
3 changes: 2 additions & 1 deletion packages/core/src/hooks/index.ts
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";
20 changes: 20 additions & 0 deletions packages/core/src/hooks/wallet.ts
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 };
}
8 changes: 8 additions & 0 deletions packages/core/src/types/wallet.ts
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;
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,11 @@
find-up "^5.0.0"
js-yaml "^4.1.0"

"@faker-js/faker@^9.5.1":
version "9.5.1"
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-9.5.1.tgz#1f32fb726db5f539415455cadbc93c9fb457e42d"
integrity sha512-0fzMEDxkExR2cn731kpDaCCnBGBUOIXEi2S1N5l8Hltp6aPf4soTMJ+g4k8r2sI5oB+rpwIW8Uy/6jkwGpnWPg==

"@floating-ui/core@^1.6.0":
version "1.6.9"
resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.6.9.tgz#64d1da251433019dafa091de9b2886ff35ec14e6"
Expand Down

0 comments on commit a719c43

Please sign in to comment.