Skip to content

Commit

Permalink
feat: Add burner wallet link once created
Browse files Browse the repository at this point in the history
  • Loading branch information
wryonik committed Sep 23, 2024
1 parent de8e704 commit dcdea45
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 56 deletions.
33 changes: 18 additions & 15 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import LandingPage from "./pages/landingPage";
import RecoverWalletFlow from "./pages/recoverWalletFlow";
import SafeWalletFlow from "./pages/safeWalletFlow";
import theme from "./theme"; // Import custom theme
import { Web3Provider } from "./providers/Web3Provider";

Check warning on line 14 in src/App.tsx

View workflow job for this annotation

GitHub Actions / eslint

`./providers/Web3Provider` import should occur before import of `./theme`

Check warning on line 14 in src/App.tsx

View workflow job for this annotation

GitHub Actions / eslint

`./providers/Web3Provider` import should occur before import of `./theme`

export const StepsContext = createContext(null);

Expand All @@ -26,21 +27,23 @@ function App() {
setStep,
}}
>
<BrowserRouter>
<NavBar />
<div style={{ padding: 16 }}>
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/safe-wallet" element={<SafeWalletFlow />} />
<Route path="/burner-wallet" element={<BurnerWalletFlow />} />
<Route
path="/wallet-recovery"
element={<RecoverWalletFlow />}
/>
<Route path="*" element={<ErrorPage />} />
</Routes>
</div>
</BrowserRouter>
<Web3Provider>
<BrowserRouter>
<NavBar />
<div style={{ padding: 16 }}>
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/safe-wallet" element={<SafeWalletFlow />} />
<Route path="/burner-wallet" element={<BurnerWalletFlow />} />
<Route
path="/wallet-recovery"
element={<RecoverWalletFlow />}
/>
<Route path="*" element={<ErrorPage />} />
</Routes>
</div>
</BrowserRouter>
</Web3Provider>
</StepsContext.Provider>
</ThemeProvider>
</AppContextProvider>
Expand Down
10 changes: 3 additions & 7 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Transition = React.forwardRef(function Transition(
props: TransitionProps & {
children: React.ReactElement;
},
ref: React.Ref<unknown>,
ref: React.Ref<unknown>
) {
return <Slide direction="up" ref={ref} {...props} />;
});
Expand Down Expand Up @@ -152,9 +152,7 @@ const MobileNav = ({
>
Learn More
</Button>
<Web3Provider>
<ConnectKitButton />
</Web3Provider>
<ConnectKitButton />
</Grid>
</Dialog>
);
Expand Down Expand Up @@ -315,9 +313,7 @@ const NavBar: React.FC = () => {
>
Learn More
</Button>
<Web3Provider>
<ConnectKitButton />
</Web3Provider>
<ConnectKitButton />
</Box>
</Grid>
</Grid>
Expand Down
39 changes: 16 additions & 23 deletions src/components/burnerWallet/GuardianSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const GuardianSetup = () => {
const [isWalletPresent, setIsWalletPresent] = useState(false);
const [emailError, setEmailError] = useState(false);
const [recoveryDelayUnit, setRecoveryDelayUnit] = useState(
TIME_UNITS.SECS.value,
TIME_UNITS.SECS.value
);
// const [recoveryExpiryUnit, setRecoveryExpiryUnit] = useState(
// TIME_UNITS.DAYS.value,
Expand Down Expand Up @@ -142,7 +142,7 @@ const GuardianSetup = () => {

const guardianSalt = await relayer.getAccountSalt(
acctCode,
guardianEmail,
guardianEmail
);

// The guardian address is generated by sending the user's account address and guardian salt to the computeEmailAuthAddress function
Expand All @@ -157,7 +157,7 @@ const GuardianSetup = () => {
const burnerWalletAddress = await run(client, safeAccount, guardianAddr);
localStorage.setItem(
"burnerWalletConfig",
JSON.stringify({ burnerWalletAddress }),
JSON.stringify({ burnerWalletAddress })
);
setIsWalletPresent(true);
} catch (error) {
Expand Down Expand Up @@ -234,26 +234,19 @@ const GuardianSetup = () => {
guardianEmail,
localStorageAccountCode,
templateIdx,
subject[0].join().replaceAll(",", " ").replace("{ethAddr}", address),
subject[0].join().replaceAll(",", " ").replace("{ethAddr}", address)
);
} catch (error) {
if (error.response?.status === 502) {
// retry mechanism as this API call fails for the first time
console.warn("502 error, retrying...");
await new Promise((resolve) => setTimeout(resolve, 1000)); // 1 second delay
await relayer.acceptanceRequest(
universalEmailRecoveryModule as `0x${string}`,
guardianEmail,
localStorageAccountCode,
templateIdx,
subject[0]
.join()
.replaceAll(",", " ")
.replace("{ethAddr}", address),
);
} else {
throw error; // Rethrow for non-502 errors
}
// retry mechanism as this API call fails for the first time
console.warn("502 error, retrying...");
await new Promise((resolve) => setTimeout(resolve, 1000)); // 1 second delay
await relayer.acceptanceRequest(
universalEmailRecoveryModule as `0x${string}`,
guardianEmail,
localStorageAccountCode,
templateIdx,
subject[0].join().replaceAll(",", " ").replace("{ethAddr}", address)
);
}

// Setting up interval for polling
Expand All @@ -263,7 +256,7 @@ const GuardianSetup = () => {
} catch (err) {
console.error(err);
toast.error(
err?.shortMessage ?? "Something went wrong, please try again.",
err?.shortMessage ?? "Something went wrong, please try again."
);
setLoading(false);
}
Expand Down Expand Up @@ -320,7 +313,7 @@ const GuardianSetup = () => {
value={recoveryDelay}
onChange={(e) =>
setRecoveryDelay(
parseInt((e.target as HTMLInputElement).value),
parseInt((e.target as HTMLInputElement).value)
)
}
title="Recovery Delay"
Expand Down
33 changes: 28 additions & 5 deletions src/pages/burnerWalletFlow.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { useContext } from "react";
import { useContext, useEffect, useState } from "react";
import { StepsContext } from "../App";
import GuardianSetup from "../components/burnerWallet/GuardianSetup";
import RequestedRecoveries from "../components/burnerWallet/RequestedRecoveries";
import { STEPS } from "../constants";
import { Web3Provider } from "../providers/Web3Provider";

const BurnerWalletFlow = () => {
const stepsContext = useContext(StepsContext);
const [burnerWalletAddress, setBurnerWalletAddress] = useState();

useEffect(() => {
const burnerWalletAddressPollingInterval = setInterval(() => {
const burnerWalletConfig = localStorage.getItem("burnerWalletConfig");
if (burnerWalletConfig !== undefined && burnerWalletConfig !== null) {
setBurnerWalletAddress(
JSON.parse(burnerWalletConfig)?.burnerWalletAddress
);
clearInterval(burnerWalletAddressPollingInterval);
}
}, 1000);
}, []);

const renderBody = () => {
switch (stepsContext?.step) {
Expand All @@ -24,9 +36,20 @@ const BurnerWalletFlow = () => {
};

return (
<Web3Provider>
<div className="app">{renderBody()}</div>
</Web3Provider>
<div className="app">
{burnerWalletAddress ? (
<>
Burner Wallet Address:{" "}
<a
href={`https://app.safe.global/home?safe=basesep%3A${burnerWalletAddress}`}
target="_blank"
>
{burnerWalletAddress}
</a>
</>
) : null}
{renderBody()}
</div>
);
};

Expand Down
4 changes: 1 addition & 3 deletions src/pages/recoverWalletFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const RecoverWalletFlow = () => {

return (
<div>
<Web3Provider>
<div className="app">{renderBody()}</div>
</Web3Provider>
<div className="app">{renderBody()}</div>
</div>
);
};
Expand Down
4 changes: 1 addition & 3 deletions src/pages/safeWalletFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const SafeWalletFlow = () => {

return (
<div>
<Web3Provider>
<div className="app">{renderBody()}</div>
</Web3Provider>
<div className="app">{renderBody()}</div>
</div>
);
};
Expand Down

0 comments on commit dcdea45

Please sign in to comment.