-
Notifications
You must be signed in to change notification settings - Fork 4
π Persist active wallet #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,7 @@ export function WalletView(props) { | |
| }) | ||
| //You may want to filter by active address array to avoid rehydration? | ||
| localStorage.setItem('addresses', JSON.stringify(remainingAddresses)) | ||
|
|
||
| setAddresses(remainingAddresses) | ||
| if (remainingAddresses.length === 0) { | ||
| dispatcher('signOut', { | ||
|
|
@@ -192,6 +193,7 @@ export function WalletView(props) { | |
| setSignedIn(false) | ||
| } | ||
| // setActiveWallet(remainingAddresses[0] || null) | ||
| persistActiveWallet(remainingAddresses[0] || addresses[0] || {}) | ||
| } | ||
|
|
||
| const peraDisconnect = (targetWallet) => { | ||
|
|
@@ -206,6 +208,7 @@ export function WalletView(props) { | |
| type: 'wallet' | ||
| }) | ||
| setSignedIn(false) | ||
| persistActiveWallet(remainingAddresses[0] || addresses[0] || {}) | ||
| // setActiveWallet(remainingAddresses[0]) | ||
| } | ||
| if (typeof targetWallet.connector.killSession !== 'undefined') | ||
|
|
@@ -241,6 +244,18 @@ export function WalletView(props) { | |
| // return signedIn ? 'default' : 'primary' | ||
| // } | ||
|
|
||
| const persistActiveWallet = (addr) => { | ||
| Object.keys(addr).length > 1 && localStorage.setItem('activeWallet', JSON.stringify(addr)) | ||
| } | ||
|
|
||
| // Set Active Wallet when page renders | ||
| useEffect(() => { | ||
| const activeWallet = JSON.parse(localStorage.getItem('activeWallet')) | ||
| if (activeWallet) { | ||
| setActiveWallet(activeWallet) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IYTEC I actually think that all we would need to do to avoid the edge case would be to check the return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! No problem, we will go through it on Monday |
||
| } | ||
| }, []) | ||
|
|
||
| const isWalletActive = (addr) => { | ||
| return activeWallet?.address === addr | ||
| } | ||
|
|
@@ -250,7 +265,13 @@ export function WalletView(props) { | |
| } | ||
|
|
||
| const handleWalletClick = async (addr) => { | ||
| !isWalletActive(addr) && setActiveWallet(addr) | ||
| // !isWalletActive(addr) && setActiveWallet(addr) | ||
| if (!isWalletActive(addr)) { | ||
| setActiveWallet(addr) | ||
| console.log(addresses, 'adddresses') | ||
| persistActiveWallet(addr) | ||
| // localStorage.setItem('activeWallet', JSON.stringify(addr)) | ||
| } | ||
| } | ||
|
|
||
| const walletsQuery = useAccountsInfo(addresses) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does JSON.parse work on a null string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't work on null string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, if there are no activeWallet, it just returns null. Nothing to set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IYTEC I like what you are doing but I am going to hold off merging this in because I do see some edge-cases with this implementation. Perhaps next week we can get hop on a call and talk about it. But for one thing,
setActiveWallet()will throw an error some of the time because the actual hook is setting the wallet on the Algodex Api instance. Since it is internally going through our API it will be subject to AJV schema validation and will throw errors when passed an empty object.