Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectride committed Feb 17, 2024
1 parent 34e1069 commit fe4393a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
34 changes: 17 additions & 17 deletions packages/nextjs/components/moon/sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useMoonSDK } from "../../hooks/moon";
//import { useCall } from "~~/hooks/call";
import { CreateAccountInput } from "@moonup/moon-api";
import { formatEther } from "viem";
import { erc20ABI } from "wagmi";
//import { erc20ABI } from "wagmi";
import { ClipboardIcon } from "@heroicons/react/24/outline";
import { InputBase, InputPwd } from "~~/components/scaffold-eth";

export const Sign = () => {
const { moon, connect, disconnect, listAccounts, contractCall } = useMoonSDK();
const { moon, connect, disconnect, listAccounts } = useMoonSDK();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [answer, setAnswer] = useState("");
Expand Down Expand Up @@ -104,19 +104,19 @@ export const Sign = () => {
}
};

const handleTransaction = async (event: React.MouseEvent<HTMLElement>) => {
event.preventDefault();
setAnswer("");
try {
await contractCall(moonWallet, "0xDED33Fff66356AaffBD03a972ef9fd91fe620D3d", erc20ABI as any, "approve", [
"0x8e185b1990573693FC74b38642B8c2f14E010d94",
10000000000000000n,
]);
} catch (error: any) {
console.error(error);
if (error) setAnswer(error.error.message);
}
};
// const handleTransaction = async (event: React.MouseEvent<HTMLElement>) => {
// event.preventDefault();
// setAnswer("");
// try {
// await contractCall(moonWallet, "0xd8992Ed72C445c35Cb4A2be468568Ed1079357c8", erc20ABI as any, "approve", [
// "0x8954AfA98594b838bda56FE4C12a09D7739D179b",
// 10000000000000000000000000n,
// ]);
// } catch (error: any) {
// console.error(error);
// if (error) setAnswer(error.error.message);
// }
// };

const handleCopy = () => {
navigator.clipboard.writeText(moonWallet);
Expand Down Expand Up @@ -160,9 +160,9 @@ export const Sign = () => {
</>
)}

<button className="btn btn-secondary" onClick={handleTransaction}>
{/*<button className="btn btn-secondary" onClick={handleTransaction}>
Test Tx
</button>
</button>*/}
</div>
);
};
7 changes: 4 additions & 3 deletions packages/nextjs/components/tournament/withdraw-moon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMoonSDK } from "~~/hooks/moon";
export const WithdrawMoon = () => {
const connectedAddress: string = useAccount()?.address ?? "";
const { moonWallet } = useMoonWalletContext();
const account = connectedAddress || moonWallet;
const chainId = 80001;

const [withdrawn, setWithdrawn] = useState(false);
Expand All @@ -32,14 +33,14 @@ export const WithdrawMoon = () => {
abi: DeployedContracts[chainId].Tournament.abi,
address: params.addr,
functionName: "withdrawAmountFromDeposit",
args: [connectedAddress],
args: [account],
});

const { data: prizeAmount } = useContractRead({
abi: DeployedContracts[chainId].Tournament.abi,
address: params.addr,
functionName: "getPrizeAmount",
args: [connectedAddress],
args: [account],
});

const handleWithdraw = async () => {
Expand All @@ -61,7 +62,7 @@ export const WithdrawMoon = () => {
abi: DeployedContracts[chainId].Tournament.abi,
eventName: "Unstaked",
listener: log => {
if (log[0].args.player == connectedAddress && (log[0].args.amount || 0n) > 0n) {
if (log[0].args.player == account && (log[0].args.amount || 0n) > 0n) {
setWithdrawn(true);
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/hooks/moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function useMoonSDK(): MoonSDKHook {
data: encodedData,
chain_id: "80001",
encoding: "utf-8",
gas: "1000000",
};

const rawTx = await moon.getAccountsSDK().signTransaction(moonWallet, data);
Expand Down

0 comments on commit fe4393a

Please sign in to comment.