AbsaOSS / rn-indy-sdk

This code was starting point of https://github.com/hyperledger/indy-sdk-react-native where the work continues.
Apache License 2.0
11 stars 6 forks source link

Error: Wallet already opened during development #41

Closed TimoGlastra closed 3 years ago

TimoGlastra commented 3 years ago

When developing with rn-indy-sdk oftentimes the JavaScript bundle is reloaded which means it will reintialize and lose the handle to the opened wallet, while it is still open. This results in errors

Scenario:

  1. Call open wallet, get wallet handle.
  2. Make change in code, fast refresh will reload JS bundle
  3. Call open wallet again because you don't have the handle anymore on the JS side
  4. Error: Wallet already opened error because wallet is still opened on native side.

This could be fixed by storing the wallet handle in persistence (e.g. react-native-async-storage), but that seems like the wrong place to solve this to me.

I think we should do some custom handling before calling the indy native open wallet method and first check if this wallet is already opened. This requires us to store some extra data (mainly wallet id, possibly more) in memory to know this wallet is already. opened If this is the case we can just return the wallet handle.

Scenario:

  1. Call open wallet, get wallet handle.
    • Wallet doesn't exist in wallet mapping already
    • Call indy open wallet method
  2. Make change in code, fast refresh will reload JS bundle
  3. Call open wallet again because you don't have the handle anymore on the JS side
    • id of the wallet exists in the wallet mapping
    • Return the already present wallet handle
  4. Success!
TimoGlastra commented 3 years ago

I took an initial shot at this. It compiles for iOS, but haven't tested it yet for both Android and iOS.

https://github.com/TimoGlastra/rn-indy-sdk/tree/fix/wallet-open

icc-romeu commented 3 years ago

I think this issue was fixed with #47 @TimoGlastra