Skip to content

Commit

Permalink
Merge branch 'add-safe-1.4-rebase' of https://github.com/zkemail/emai…
Browse files Browse the repository at this point in the history
…l-recovery-demo into add-safe-1.4-rebase
  • Loading branch information
wshino committed Sep 17, 2024
2 parents 603fd8b + 066ca68 commit 662d84a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 46 deletions.
14 changes: 12 additions & 2 deletions src/components/GuardianSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,23 @@ const GuardianSetup = () => {

console.debug("recovery configured");

const command = getRequestGuardianCommand(address);
// const command = getRequestGuardianCommand(address);

const command = await readContract(config, {
abi: safeEmailRecoveryModuleAbi,
address: safeEmailRecoveryModule as `0x${string}`,
functionName: "acceptanceCommandTemplates",
args: [],
});

console.log(command[0].join().replace(',', ' ').replace('{ethAddr}', address), "command")

const { requestId } = await relayer.acceptanceRequest(
safeEmailRecoveryModule as `0x${string}`,
guardianEmail,
acctCode,
templateIdx,
command
command[0].join()?.replaceAll(',', ' ').replaceAll('{ethAddr}', address)
);

console.debug("accept req id", requestId);
Expand Down
27 changes: 14 additions & 13 deletions src/components/RequestedRecoveries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ const RequestedRecoveries = () => {

console.log(getRecoveryRequest.currentWeight, getGuardianConfig.threshold);

// if (getRecoveryRequest.currentWeight < getGuardianConfig.threshold && getGuardianConfig.threshold!==0n) {
// setButtonState(BUTTON_STATES.TRIGGER_RECOVERY);
// } else {
// setButtonState(BUTTON_STATES.COMPLETE_RECOVERY);
// setLoading(false);
// clearInterval(interval);
// }
if (getRecoveryRequest.currentWeight < getGuardianConfig.threshold) {
setButtonState(BUTTON_STATES.TRIGGER_RECOVERY);
} else {
setButtonState(BUTTON_STATES.COMPLETE_RECOVERY);
setLoading(false);
clearInterval(interval);
}
setIsButtonStateLoading(false);
};

Expand Down Expand Up @@ -119,18 +119,19 @@ const RequestedRecoveries = () => {
);
}

const command = getRequestsRecoveryCommandForSafe13(
safeOwnersData[0],
safeWalletAddress,
newOwner
);
const command = await readContract(config, {
abi: safeEmailRecoveryModuleAbi,
address: safeEmailRecoveryModule as `0x${string}`,
functionName: "recoveryCommandTemplates",
args: [],
});

try {
const { requestId } = await relayer.recoveryRequest(
safeEmailRecoveryModule as string,
guardianEmailAddress,
templateIdx,
command
command[0].join()?.replaceAll(',', ' ').replace('{ethAddr}', safeWalletAddress).replace('{ethAddr}', safeOwnersData[0]).replace('{ethAddr}', newOwner)
);
setGuardianRequestId(requestId);

Expand Down
28 changes: 0 additions & 28 deletions src/components/burnerWallet/GuardianSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,32 +251,6 @@ const GuardianSetup = () => {
}
);

// const guardianSalt = await relayer.getAccountSalt(
// acctCode,
// guardianEmail
// );
// const guardianAddr = await readContract(config, {
// abi: universalEmailRecoveryModuleAbi,
// address: universalEmailRecoveryModule as `0x${string}`,
// functionName: "computeEmailAuthAddress",
// args: [address, guardianSalt],
// });

// await writeContractAsync({
// abi: universalEmailRecoveryModuleAbi,
// address: universalEmailRecoveryModule as `0x${string}`,
// functionName: "configureRecovery",
// args: [
// [guardianAddr],
// [1n],
// 1n,
// recoveryDelay * TIME_UNITS[recoveryDelayUnit].multiplier,
// recoveryExpiry * 60 * 60 * 24 * 30,
// ],
// });

console.debug("recovery configured");

const subject = getRequestGuardianCommand(address);
const { requestId } = await relayer.acceptanceRequest(
universalEmailRecoveryModule as `0x${string}`,
Expand All @@ -286,8 +260,6 @@ const GuardianSetup = () => {
subject
);

console.debug("accept req id", requestId);

// Setting up interval for polling
interval = setInterval(() => {

Check warning on line 264 in src/components/burnerWallet/GuardianSetup.tsx

View workflow job for this annotation

GitHub Actions / eslint

Assignments to the 'interval' variable from inside React Hook useCallback will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useCallback
checkIfRecoveryIsConfigured();
Expand Down
12 changes: 9 additions & 3 deletions src/pages/landingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import gnosisSafeLogo from "../assets/gnosis-safe-logo.svg";
import AccountBalanceWalletOutlinedIcon from "@mui/icons-material/AccountBalanceWalletOutlined";
import Toggle from "../components/Toggle";
import { Link } from "react-router-dom";
import { useState } from "react";
import { useContext, useState } from "react";
import FlowInfoCard from "../components/FlowsInfoCard";
import { STEPS } from "../constants";
import { StepsContext } from "../App";

type actionType = "SAFE_WALLET" | "BURNER_WALLET" | "WALLET_RECOVERY";
type FlowType = "setup" | "recover";

const LandingPage = () => {
const theme = useTheme();
const [flow, setFlow] = useState<FlowType>("setup");
const stepsContext = useContext(StepsContext);

const navigate = useNavigate();

Expand All @@ -25,12 +28,15 @@ const LandingPage = () => {
};

const handleClick = async (action: actionType) => {
await stepsContext?.setStep(STEPS.CONNECT_WALLETS);
await localStorage.removeItem('accountCode')
await localStorage.removeItem('burnerWalletConfig')


switch (action) {
case "SAFE_WALLET":
return navigate("/safe-wallet");
case "BURNER_WALLET":
await localStorage.removeItem('accountCode')
await localStorage.removeItem('burnerWalletConfig')
return navigate("/burner-wallet");
case "WALLET_RECOVERY":
return navigate("/wallet-recovery");
Expand Down

0 comments on commit 662d84a

Please sign in to comment.