Skip to content

Commit

Permalink
show session reward factors on status page
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Nov 1, 2023
1 parent 3fd79dd commit 2995b0b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
40 changes: 40 additions & 0 deletions faucet-client/src/components/status/FaucetStatusPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ export class FaucetStatusPage extends React.PureComponent<IFaucetStatusPageProps
);
}

if(session.factor && session.factor.length > 0) {
let totalFactor = 1;
session.factor.forEach((f) => {
totalFactor *= f.factor;
});
sessionStatus.push(
<OverlayTrigger
placement="auto"
delay={{ show: 250, hide: 400 }}
overlay={(props) => this.renderFactorInfo(session, props)}
>
<span key="factor" className={["badge", "bg-info"].join(" ")}>x{Math.round(totalFactor * 100) / 100}</span>
</OverlayTrigger>
);
}

return (
<tr key={session.id}>
<th scope="row">{session.id}</th>
Expand Down Expand Up @@ -409,6 +425,30 @@ export class FaucetStatusPage extends React.PureComponent<IFaucetStatusPageProps
);
}

private renderFactorInfo(session: IClientSessionStatus, props: any): React.ReactElement {
if(!session.factor)
return null;

return (
<Tooltip id="ipinfo-tooltip" {...props}>
<div className='ipaddr-info'>
<table>
<tbody>
{session.factor.map((f) => {
return (
<tr>
<td className='ipinfo-title'>x{Math.round(f.factor * 100) / 100}</td>
<td className='ipinfo-value'>{f.module} {f.name ? "/" + f.name : ""}</td>
</tr>
);
})}
</tbody>
</table>
</div>
</Tooltip>
);
}

private renderActiveClaims(): React.ReactElement {
return (
<table className="table table-striped status-sessions">
Expand Down
9 changes: 8 additions & 1 deletion faucet-client/src/types/FaucetStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IClientSessionStatus {
boost: any;
connected: boolean;
idle: number;
factor: ISessionRewardFactor[];
}

export interface IClientClaimStatusRsp {
Expand Down Expand Up @@ -92,4 +93,10 @@ export interface IClientSessionRestrictionStatus {
notify: boolean|string;
}[];
blocked: false|"close"|"kill";
}
}

export interface ISessionRewardFactor {
factor: number;
module: string;
name?: string;
}
1 change: 1 addition & 0 deletions src/session/FaucetSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export class FaucetSession {

let rewardFactors: ISessionRewardFactor[] = [];
await ServiceManager.GetService(ModuleManager).processActionHooks([], ModuleHookAction.SessionRewardFactor, [this, rewardFactors]);
this.setSessionData("reward.factors", rewardFactors);

let rewardFactor = 1;
//console.log(rewardFactors);
Expand Down
3 changes: 3 additions & 0 deletions src/webserv/api/faucetStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FaucetBalanceModule } from "../../modules/faucet-balance/FaucetBalanceM
import { FaucetOutflowModule } from "../../modules/faucet-outflow/FaucetOutflowModule";
import { ModuleManager } from "../../modules/ModuleManager";
import { SessionManager } from "../../session/SessionManager";
import { ISessionRewardFactor } from "../../session/SessionRewardFactor";
import { getHashedIp, getHashedSessionId } from "../../utils/HashedInfo";

export interface IClientClaimStatus {
Expand Down Expand Up @@ -37,6 +38,7 @@ export interface IClientSessionStatus {
boost: any;
connected: boolean;
idle: number;
factors: ISessionRewardFactor[];
}

export interface IClientFaucetStatus {
Expand Down Expand Up @@ -125,6 +127,7 @@ export async function buildSessionStatus(unmasked?: boolean): Promise<IClientSes
boost: session.data["passport.score"],
connected: runningSession ? !!runningSession.getSessionModuleRef("pow.client") : null,
idle: session.data["pow.idleTime"],
factors: session.data["reward.factors"],
}
});

Expand Down
4 changes: 2 additions & 2 deletions static/js/powfaucet.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/powfaucet.js.map

Large diffs are not rendered by default.

0 comments on commit 2995b0b

Please sign in to comment.