fungible-systems / micro-stacks

Tiny libraries for building the next generation of Stacks apps.
https://micro-stacks.dev
MIT License
82 stars 15 forks source link

micro-stacks.store value always has Mainnet address #158

Closed akornato closed 1 year ago

akornato commented 1 year ago

micro-stacks.store local storage value always has Mainnet address, even if there's both network="testnet" supplied to ClientProvider and Hiro Wallet signs in to Testnet. Same for ClientProvider onPersistState dehydratedState, so it seems impossible to SSR correctly on Testnet becauseuseAccount stxAddress is always the Mainnet one (even though useNetwork isMainnet is correctly false).

aulneau commented 1 year ago

This is a known issue, in that if there is a saved state of mainnet in the users session, eg saved to cookie or in localstorage, the network= value in the client provider will be ignored.

I will be pushing an update this week that will change the behavior of the network value, such that folks can either force the setting of network via that value, or have it be set as the "default" value, which if there is a different value for the user session, it will be ignored.

aulneau commented 1 year ago

To test and make sure this is the case, can you clear all application data (localStorage, cookies, etc), and make sure testnet is the value, and then determine that it's either testnet or mainnet on the server?

Also, if you can share a reproduction or repo for your project, that would help.

aulneau commented 1 year ago

fixed with https://github.com/fungible-systems/micro-stacks/pull/159

aulneau commented 1 year ago

Please update your dependencies to their latest versions and let me know if you run into any issues!

akornato commented 1 year ago

@aulneau with your fix #159 (thanks for the PR to my repo!) the lib is updating the local storage & cookie when signing out/in, but it's still putting Mainnet address in them even if there's both network="testnet" supplied to ClientProvider and Hiro Wallet signs in to Testnet. My repo is https://github.com/akornato/stacks-dashboard deployed at https://stacks-dashboard.vercel.app

aulneau commented 1 year ago

@akornato I just tried out your project and found it to behave as I expect:

If you do not pass enableNetworkSwitching to the config, the value saved to localStorage or cookie will be ignored, and the only value that matters is what is passed to the Config provider.

Does this help? If you have other questions please let me know!

akornato commented 1 year ago

@aulneau indeed useAccount and useCurrentStxAddress are now returning Testnet address on the server correctly, that's great! However the dehydratedState I'm accessing in getServerSideProps still has Mainnet address. I need the Testnet address there to be able to fetch correct data for Testnet address on the server.

vicnicius commented 10 months ago

Is there a solution to accessing the testnet address from the dehydratedState when using getServerSideProps?