Skip to content
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

feat(core): switching networks #187

Merged
merged 12 commits into from
Jun 19, 2024
Merged

Conversation

drichar
Copy link
Collaborator

@drichar drichar commented Jun 18, 2024

Description

This ensures that the consuming app is properly updated whenever the active network is changed. The Algod client used internally by wallets is set to a property in the WalletManager class, but in the consuming app it needs to be reactive.

So the framework adapters now handle the creation of new Algodv2 clients on mount and when the network is changed. It is stored it in a reactive variable and synced to the manager's algodClient property.

A new setActiveNetwork function is exported from useWallet which updates the store then creates a new Algod client with the new network's config, setting it to the reactive variable and manager.algodClient simultaneously. Both variables are referentially equal.

(When using the core library only, the process of changing active networks remains the same.)

⚠️ BREAKING CHANGE

In the Vue adapter, the reactive algodClient is a computed ref object and must now be accessed by its value property, e.g.,

import { useWallet } from '@txnlab/use-wallet-vue'

const { algodClient } = useWallet()
- const suggestedParams = await algodClient.getTransactionParams().do()
+ const suggestedParams = await algodClient.value.getTransactionParams().do()

Disconnect all wallets on network change

When the network changes all connected wallets are disconnected. This is a new feature. Most wallets require the user to reconnect before transactions for a different network can be signed.

Refactors React and SolidJS adapters

To keep these two framework adapters as simple as possible, all of the source code is combined into a single file.

Other changes

  • Fixes some tests that I previously couldn't get to pass, that were being skipped
  • Adds a "network switcher" to the example apps to demonstrate switching networks

This also refactors the `useWallet` hook so it directly accesses `WalletContext` (in place of the `useWalletManager` hook).

Both modules are now in a single file - src/index.tsx
@drichar drichar force-pushed the feat/adapters-handle-algod-client branch from 55c0c40 to 155e2f8 Compare June 18, 2024 09:30
@drichar drichar added the v3 label Jun 18, 2024
@drichar drichar added this to the v3.0.0 stable release milestone Jun 18, 2024
@drichar drichar changed the title feat(core): reactive algodClient in framework adapters feat(core): switching networks Jun 18, 2024
@drichar drichar force-pushed the feat/adapters-handle-algod-client branch from 19a4a37 to 56f7528 Compare June 19, 2024 06:52
@drichar drichar merged commit ef07c4d into v3 Jun 19, 2024
1 check passed
@drichar drichar deleted the feat/adapters-handle-algod-client branch June 19, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant