From b6b2b8acf83ae6e80b8ac3d8a8d901d93e479dcf Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Tue, 26 Mar 2024 19:53:12 -0700 Subject: [PATCH] persist input data for muxed account --- .nvmrc | 2 +- .../(sidebar)/account/muxed-create/page.tsx | 14 +++++++++--- .../(sidebar)/account/muxed-parse/page.tsx | 5 ++++- src/store/createStore.ts | 22 +++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.nvmrc b/.nvmrc index 3462e8c26..0828ab794 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v18.19.0 \ No newline at end of file +v18 \ No newline at end of file diff --git a/src/app/(sidebar)/account/muxed-create/page.tsx b/src/app/(sidebar)/account/muxed-create/page.tsx index 6f81ec14f..21a3135e5 100644 --- a/src/app/(sidebar)/account/muxed-create/page.tsx +++ b/src/app/(sidebar)/account/muxed-create/page.tsx @@ -17,9 +17,12 @@ import "../styles.scss"; export default function CreateMuxedAccount() { const { account } = useStore(); - const [baseAddress, setBaseAddress] = useState(""); - const [muxedId, setMuxedId] = useState(""); - + const [baseAddress, setBaseAddress] = useState( + account.generatedMuxedAccountInput.baseAddress || "", + ); + const [muxedId, setMuxedId] = useState( + account.generatedMuxedAccountInput.id || "", + ); const [baseFieldErrorMessage, setBaseFieldErrorMessage] = useState(""); const [muxedFieldError, setMuxedFieldError] = useState(""); @@ -43,6 +46,11 @@ export default function CreateMuxedAccount() { muxedAddress, }); + account.updateGeneratedMuxedAccountInput({ + id: muxedId, + baseAddress, + }); + setSdkError(""); return; } diff --git a/src/app/(sidebar)/account/muxed-parse/page.tsx b/src/app/(sidebar)/account/muxed-parse/page.tsx index 04f16b8c1..607c00161 100644 --- a/src/app/(sidebar)/account/muxed-parse/page.tsx +++ b/src/app/(sidebar)/account/muxed-parse/page.tsx @@ -18,7 +18,9 @@ export default function ParseMuxedAccount() { const { account } = useStore(); const parsedMuxedAccount = account.parsedMuxedAccount; - const [muxedAddress, setMuxedAddress] = useState(""); + const [muxedAddress, setMuxedAddress] = useState( + account.parsedMuxedAccountInput || "", + ); const [muxedFieldError, setMuxedFieldError] = useState(""); const [sdkError, setSdkError] = useState(""); @@ -39,6 +41,7 @@ export default function ParseMuxedAccount() { baseAddress, muxedAddress, }); + account.updateParsedMuxedAccountInput(muxedAddress); setSdkError(""); return; diff --git a/src/store/createStore.ts b/src/store/createStore.ts index 22d0aa42c..2cc4bea20 100644 --- a/src/store/createStore.ts +++ b/src/store/createStore.ts @@ -15,11 +15,17 @@ export interface Store { // Account account: { publicKey: string; + generatedMuxedAccountInput: Partial; generatedMuxedAccount: MuxedAccount; + parsedMuxedAccountInput: string | undefined; parsedMuxedAccount: MuxedAccount; // eslint-disable-next-line no-unused-vars updatePublicKey: (value: string) => void; // eslint-disable-next-line no-unused-vars + updateGeneratedMuxedAccountInput: (value: Partial) => void; + // eslint-disable-next-line no-unused-vars + updateParsedMuxedAccountInput: (value: string) => void; + // eslint-disable-next-line no-unused-vars updateGeneratedMuxedAccount: (value: MuxedAccount) => void; // eslint-disable-next-line no-unused-vars updateParsedMuxedAccount: (value: MuxedAccount) => void; @@ -78,16 +84,32 @@ export const createStore = (options: CreateStoreOptions) => // Account account: { publicKey: "", + generatedMuxedAccountInput: { + id: undefined, + baseAddress: undefined, + }, generatedMuxedAccount: { id: undefined, baseAddress: undefined, muxedAddress: undefined, }, + parsedMuxedAccountInput: undefined, parsedMuxedAccount: { id: undefined, baseAddress: undefined, muxedAddress: undefined, }, + updateGeneratedMuxedAccountInput: (value: Partial) => + set((state) => { + state.account.generatedMuxedAccountInput = { + ...state.account.generatedMuxedAccountInput, + ...value, + }; + }), + updateParsedMuxedAccountInput: (value: string) => + set((state) => { + state.account.parsedMuxedAccountInput = value; + }), updateGeneratedMuxedAccount: (newMuxedAccount: MuxedAccount) => set((state) => { state.account.generatedMuxedAccount = {