Skip to content

Commit

Permalink
persist input data for muxed account
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeesun Kim authored and Jeesun Kim committed Mar 27, 2024
1 parent adf59ad commit b6b2b8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v18
14 changes: 11 additions & 3 deletions src/app/(sidebar)/account/muxed-create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import "../styles.scss";
export default function CreateMuxedAccount() {
const { account } = useStore();

const [baseAddress, setBaseAddress] = useState<string>("");
const [muxedId, setMuxedId] = useState<string>("");

const [baseAddress, setBaseAddress] = useState<string>(
account.generatedMuxedAccountInput.baseAddress || "",
);
const [muxedId, setMuxedId] = useState<string>(
account.generatedMuxedAccountInput.id || "",
);
const [baseFieldErrorMessage, setBaseFieldErrorMessage] =
useState<string>("");
const [muxedFieldError, setMuxedFieldError] = useState<string>("");
Expand All @@ -43,6 +46,11 @@ export default function CreateMuxedAccount() {
muxedAddress,
});

account.updateGeneratedMuxedAccountInput({
id: muxedId,
baseAddress,
});

setSdkError("");
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/(sidebar)/account/muxed-parse/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default function ParseMuxedAccount() {
const { account } = useStore();
const parsedMuxedAccount = account.parsedMuxedAccount;

const [muxedAddress, setMuxedAddress] = useState<string>("");
const [muxedAddress, setMuxedAddress] = useState<string>(
account.parsedMuxedAccountInput || "",
);

const [muxedFieldError, setMuxedFieldError] = useState<string>("");
const [sdkError, setSdkError] = useState<string>("");
Expand All @@ -39,6 +41,7 @@ export default function ParseMuxedAccount() {
baseAddress,
muxedAddress,
});
account.updateParsedMuxedAccountInput(muxedAddress);

setSdkError("");
return;
Expand Down
22 changes: 22 additions & 0 deletions src/store/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ export interface Store {
// Account
account: {
publicKey: string;
generatedMuxedAccountInput: Partial<MuxedAccount>;
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<MuxedAccount>) => 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;
Expand Down Expand Up @@ -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<MuxedAccount>) =>
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 = {
Expand Down

0 comments on commit b6b2b8a

Please sign in to comment.