commit 5627896757d8ff7418f0db6e50478eda521df84f
parent 2aaa2e999a034f5020eb8ef4a21a8fe71d92ff74
Author: Sebastian <sebasjm@gmail.com>
Date: Wed, 21 Aug 2024 10:24:17 -0300
do not require state
Diffstat:
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/packages/challenger-ui/src/hooks/session.ts b/packages/challenger-ui/src/hooks/session.ts
@@ -102,16 +102,14 @@ export function useSessionState(): SessionStateHandler {
});
},
removeAddress(index) {
- if (!state) throw Error("should have an state");
const lastAddr = [...(state?.lastAddress ?? [])];
lastAddr.splice(index, 1);
update({
- ...state,
+ completedURL: undefined,
lastAddress: lastAddr,
});
},
saveAddress(type, address) {
- if (!state) throw Error("should have an state");
const lastAddr = [...(state?.lastAddress ?? [])];
lastAddr.push({
type,
@@ -119,24 +117,26 @@ export function useSessionState(): SessionStateHandler {
savedAt: AbsoluteTime.now(),
});
update({
- ...state,
+ completedURL: undefined,
lastAddress: lastAddr,
});
},
sent(info) {
- if (!state) throw Error("should have an state");
- // instead of reloading state from server we can update client state
},
failed(info) {
- if (!state) throw Error("should have an state");
- // instead of reloading state from server we can update client state
},
completed(info) {
- if (!state) throw Error("should have an state");
- update({
- ...state,
- completedURL: info.redirect_url,
- });
+ if (!state) {
+ update({
+ completedURL: info.redirect_url,
+ lastAddress: [],
+ });
+ } else {
+ update({
+ completedURL: info.redirect_url,
+ lastAddress: state.lastAddress,
+ });
+ }
},
};
}