Skip to content

Commit

Permalink
feat: mockLapuVaultFundPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
singyiu committed Oct 21, 2023
1 parent 43208df commit 061e1ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/client/src/components/ui/tutorialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getState } from "@/game/store";
import { useState, useEffect } from "react";
import { useSpring, animated, config } from "@react-spring/web";

import { useMUD } from "@/useMUD";

function TutorialModal({
step,
screenIndex,
Expand Down Expand Up @@ -75,6 +77,11 @@ function TutorialModal({
}

const Tutorial = () => {
const {
systemCalls: { mockLapuVaultFundPlayer },
} = useMUD();
const playerAddress = getState().player?.playerData?.address;

const [currentTutorial, setCurrentTutorial] = useState<
TutorialStep | undefined
>(undefined);
Expand Down Expand Up @@ -119,6 +126,8 @@ const Tutorial = () => {
} else {
setScreenIndex(screenIndex + 1);
}

mockLapuVaultFundPlayer(playerAddress);
}}
/>
)}
Expand Down
16 changes: 16 additions & 0 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ export function createSystemCalls(

const depositDaiToLapuVaultForTheConnectedPlayer = async (amount) => {
const gameSetting = await getComponentValue(GameSetting, singletonEntity);
console.log("gameSetting?.lapuVaultAddress", gameSetting?.lapuVaultAddress);
console.log(
"depositDaiToLapuVaultForTheConnectedPlayer walletClient?.account.address",
walletClient?.account.address
);
const { request } = await publicClient.simulateContract({
address: gameSetting?.lapuVaultAddress,
abi: ILapuVaultAbi,
Expand Down Expand Up @@ -304,6 +309,16 @@ export function createSystemCalls(
return data;
};

const mockLapuVaultFundPlayer = async (playerAddress, amount = 1000) => {
console.log("mockLapuVaultFundPlayer start", playerAddress, amount);
await mudMockDaiFaucet(playerAddress, amount);
console.log("mudMockDaiFaucet done");
await approveDaiToLapuVaultForTheConnectedPlayer(amount);
console.log("approveDaiToLapuVaultForTheConnectedPlayer done");
await depositDaiToLapuVaultForTheConnectedPlayer(amount);
console.log("mockLapuVaultFundPlayer done", playerAddress, amount);
};

return {
increment,
mudGetEntityType,
Expand All @@ -327,5 +342,6 @@ export function createSystemCalls(
mudMockYieldGenerationFromDeFiPool,
mudMockReleaseRewardToPlayer,
lapuVaultGetTotalSupply,
mockLapuVaultFundPlayer,
};
}
10 changes: 6 additions & 4 deletions packages/client/src/mudExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export const MudExample = () => {
mudDefiLapuBalanceOf,
mudDefiConsumesLapuFromPlayer,
mudDefiGetTotalRewardBalance,
mudMockYieldGenerationFromDeFiPool,
mudMockReleaseRewardToPlayer,
//mudMockYieldGenerationFromDeFiPool,
//mudMockReleaseRewardToPlayer,
lapuVaultGetTotalSupply,
},
} = useMUD();

const defaultTestAmount = 1000;
const defaultConsumeAmount = 100;
const defaultYieldAmount = 50;
const defaultRewardAmount = 30;
//const defaultYieldAmount = 50;
//const defaultRewardAmount = 30;

const counter = useComponentValue(Counter, singletonEntity);
const gameSetting = useComponentValue(GameSetting, singletonEntity);
Expand Down Expand Up @@ -74,6 +74,7 @@ export const MudExample = () => {
lapuVaultGetTotalSupply,
]);

/*
useEffect(() => {
const generateYieldIntervalId = setInterval(() => {
mudMockYieldGenerationFromDeFiPool(defaultYieldAmount);
Expand All @@ -91,6 +92,7 @@ export const MudExample = () => {
clearInterval(rewardPlayerIntervalId);
};
}, [playerAddress, mudMockReleaseRewardToPlayer]);
*/

const delay = async (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand Down

0 comments on commit 061e1ea

Please sign in to comment.