Skip to content

Commit

Permalink
Use balance before swap to display rank emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
CRBl69 committed Dec 2, 2024
1 parent d2cff1e commit 5094bc1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/typescript/frontend/src/lib/utils/get-user-rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export enum RankName {
*/
export const getRankFromEvent = <
T extends
| Pick<SwapEventModel["swap"], "balanceAsFractionOfCirculatingSupplyAfterQ64">
| Pick<
SwapEventModel["swap"],
| "balanceAsFractionOfCirculatingSupplyAfterQ64"
| "balanceAsFractionOfCirculatingSupplyBeforeQ64"
| "isSell"
>
| Pick<ChatEventModel["chat"], "balanceAsFractionOfCirculatingSupplyQ64">,
>(
event: T
Expand All @@ -29,8 +34,13 @@ export const getRankFromEvent = <
rankName: RankName;
} => {
const fraction = (() => {
if ("balanceAsFractionOfCirculatingSupplyAfterQ64" in event) {
const q64 = event.balanceAsFractionOfCirculatingSupplyAfterQ64;
if ("isSell" in event) {
let q64: bigint;
if (event.isSell) {
q64 = event.balanceAsFractionOfCirculatingSupplyBeforeQ64;
} else {
q64 = event.balanceAsFractionOfCirculatingSupplyAfterQ64;
}
return q64ToBig(q64).toNumber();
} else {
const q64 = event.balanceAsFractionOfCirculatingSupplyQ64;
Expand Down

0 comments on commit 5094bc1

Please sign in to comment.