Skip to content

Commit

Permalink
feat: totalRewarded
Browse files Browse the repository at this point in the history
  • Loading branch information
singyiu committed Oct 20, 2023
1 parent 507c8e1 commit 1235e0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/client/src/mudExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useState, useEffect } from "react";

export const MudExample = () => {
const {
components: { Counter },
components: { Counter, GameSetting },
systemCalls: {
mudDefiDaiBalanceOf,
mudMockDaiFaucet,
Expand All @@ -30,6 +30,7 @@ export const MudExample = () => {
const defaultRewardAmount = 30;

const counter = useComponentValue(Counter, singletonEntity);
const gameSetting = useComponentValue(GameSetting, singletonEntity);
const playerAddress = getState().player?.playerData?.address;
const [playerDaiBalance, setPlayerDaiBalance] = useState<number | null>(null);
const [playerLapuBalance, setPlayerLapuBalance] = useState<number | null>(
Expand Down Expand Up @@ -99,6 +100,10 @@ export const MudExample = () => {
Reward balance:{" "}
<span>{totalRewardBalance?.toString() ?? "??"} LAPU</span>
</div>
<div>
Total rewarded:{" "}
<span>{gameSetting?.totalRewarded?.toString() ?? "??"}</span>
</div>
<div>
Counter: <span>{counter?.value ?? "??"}</span>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default mudConfig({
defiPoolAddress: "address",
daiAddress: "address",
lapuVaultAddress: "address",
totalRewarded: "uint256",
},
},
Position: {
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/systems/MockSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ contract MockSystem is System {
function mockReleaseRewardToPlayer(address account, uint256 amount) public {
ILapuVault lapuVault = ILapuVault(GameSetting.getLapuVaultAddress());
lapuVault.transfer(account, amount);
uint256 currentTotalRewarded = GameSetting.getTotalRewarded();
GameSetting.setTotalRewarded(currentTotalRewarded + amount);
}
}

0 comments on commit 1235e0f

Please sign in to comment.