Skip to content

Commit

Permalink
set new wallet birthday to chain tip unless overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Oct 18, 2024
1 parent a333fe4 commit a2448e6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/demo-wallet/src/App/components/AddAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FormEvent, useContext, useState } from "react";
import React, { FormEvent, useContext, useEffect, useState } from "react";

import Button from "react-bootstrap/Button";
import Form from "react-bootstrap/Form";
Expand All @@ -12,17 +12,25 @@ import { NU5_ACTIVATION } from "../Constants";
export function AddAccount() {
let { state, dispatch } = useContext(WalletContext);

let [birthdayHeight, setBirthdayHeight] = useState(NU5_ACTIVATION);
let [birthdayHeight, setBirthdayHeight] = useState(0);
let [seedPhrase, setSeedPhrase] = useState("");

useEffect(() => {
const fetchBirthday = async () => {
let birthday = await state.webWallet?.get_latest_block();
setBirthdayHeight(Number(birthday) || 0);
}
fetchBirthday();
}, [state]);

const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
await addNewAccount(state, dispatch, seedPhrase, birthdayHeight);
toast.success("Account imported successfully", {
position: "top-center",
autoClose: 2000,
});
setBirthdayHeight(NU5_ACTIVATION);
setBirthdayHeight(0);
setSeedPhrase("");
flushDbToStore(state, dispatch);
};
Expand All @@ -31,7 +39,7 @@ export function AddAccount() {
const newSeedPhrase = generate_seed_phrase();
let birthday = await state.webWallet?.get_latest_block();
setSeedPhrase(newSeedPhrase);
setBirthdayHeight(Number(birthday) || NU5_ACTIVATION);
setBirthdayHeight(Number(birthday) || 0);
};

return (
Expand Down

0 comments on commit a2448e6

Please sign in to comment.