This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
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 #1410 from ecency/feature/activity-points-queries
Feature/activity points queries
- Loading branch information
Showing
35 changed files
with
276 additions
and
722 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,15 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { usrActivity } from "./private-api"; | ||
|
||
interface Params { | ||
bl?: string | number; | ||
tx?: string | number; | ||
} | ||
|
||
export function useUserActivity(username: string | undefined, ty: number) { | ||
return useMutation(["user-activity", username, ty], async (params: Params | undefined) => { | ||
if (username) { | ||
await usrActivity(username, ty, params?.bl, params?.tx); | ||
} | ||
}); | ||
} |
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
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,37 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { QueryIdentifiers } from "../core"; | ||
import { getPoints, getPointTransactions } from "./private-api"; | ||
import { useMappedStore } from "../store/use-mapped-store"; | ||
|
||
const DEFAULT = { | ||
points: "0.000", | ||
uPoints: "0.000", | ||
transactions: [] | ||
}; | ||
|
||
export function usePointsQuery(username: string, filter = 0) { | ||
const { global } = useMappedStore(); | ||
|
||
return useQuery( | ||
[QueryIdentifiers.POINTS, username, filter], | ||
async () => { | ||
const name = username.replace("@", ""); | ||
|
||
try { | ||
const points = await getPoints(name, global.usePrivate); | ||
const transactions = await getPointTransactions(name, filter); | ||
return { | ||
points: points.points, | ||
uPoints: points.unclaimed_points, | ||
transactions | ||
}; | ||
} catch (e) { | ||
return DEFAULT; | ||
} | ||
}, | ||
{ | ||
initialData: DEFAULT, | ||
retryDelay: 30000 | ||
} | ||
); | ||
} |
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
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
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
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
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
Oops, something went wrong.