Skip to content

feat: refactor network provider#144

Merged
fmorency merged 6 commits intoliftedinit:mainfrom
fmorency:design-update
Sep 29, 2023
Merged

feat: refactor network provider#144
fmorency merged 6 commits intoliftedinit:mainfrom
fmorency:design-update

Conversation

@fmorency
Copy link
Copy Markdown
Contributor

Reconcile code from liftedinit/gwen#75 and automate some boilerplate.

@fmorency fmorency added the enhancement New feature or request label Sep 27, 2023
@fmorency fmorency self-assigned this Sep 27, 2023
@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 27, 2023

Deploy Preview for lifted-alberto ready!

Name Link
🔨 Latest commit 0466a7b
🔍 Latest deploy log https://app.netlify.com/sites/lifted-alberto/deploys/6515be94f775c50007c6b8b2
😎 Deploy Preview https://deploy-preview-144--lifted-alberto.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

expireInSecs,
}: MultisigDefaults) => {
const res = await n?.account.multisigSetDefaults({
return await n?.account.multisigSetDefaults({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple code inlining changes.

Comment on lines +37 to +41
const legacy = legacy_urls?.map(url => {
const n = new Network(url, anonymous)
n.apply([Account, Events])
return n
})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

END was dropped. Only care about Manifest.

Comment on lines +17 to +32
const initialNetworks: NetworkInfo[] = [
{
name: "Manifest Ledger",
url: "/api",
filter: "alberto",
},
{
name: "Manifest Ledger (Alpha 1)",
url: "/api/legacy",
filter: "legacy",
},
]

const networksMap: Map<NetworkId, NetworkInfo> = new Map(
initialNetworks.map((network, index) => [index, network]),
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the network creation boilerplate. The network Map is created automatically from the initial network list.


const devDomains = ["localhost", "liftedinit.tech"]

export const useNetworkStore = create<NetworksState & NetworksActions>(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified some code here as well.

@fmorency fmorency marked this pull request as draft September 27, 2023 14:18
Comment on lines +53 to +57
const activeNetwork = get().getActiveNetwork()
return Array.from(get().networks.values()).filter(
({ filter, parent }) =>
filter === "legacy" && parent?.includes(activeNetwork.name),
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only return legacy networks matching the parent

@fmorency
Copy link
Copy Markdown
Contributor Author

I can't run the pre-commit tests because of a glibc compatibility issue. Can someone run those, please?

@fmorency fmorency marked this pull request as ready for review September 27, 2023 14:38
@fmorency
Copy link
Copy Markdown
Contributor Author

Checking CI issue...

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 27, 2023

Codecov Report

Merging #144 (0466a7b) into main (3b8894a) will increase coverage by 0.35%.
The diff coverage is 74.50%.

@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
+ Coverage   34.08%   34.43%   +0.35%     
==========================================
  Files          88       88              
  Lines        2265     2262       -3     
  Branches      659      654       -5     
==========================================
+ Hits          772      779       +7     
+ Misses       1482     1472      -10     
  Partials       11       11              
Files Coverage Δ
src/features/accounts/api/get-account-info.ts 41.66% <100.00%> (ø)
src/features/balances/queries.ts 96.15% <100.00%> (ø)
...s/network/components/network-menu/network-menu.tsx 90.90% <100.00%> (+0.49%) ⬆️
src/features/network/network-provider.tsx 100.00% <100.00%> (ø)
src/views/home/home.tsx 100.00% <100.00%> (ø)
src/features/accounts/api/add-roles.ts 0.00% <0.00%> (ø)
src/features/accounts/api/get-multisig-txn-info.ts 3.12% <0.00%> (ø)
src/features/accounts/api/multisig-approve.ts 0.00% <0.00%> (ø)
src/features/accounts/api/multisig-execute.ts 0.00% <0.00%> (ø)
src/features/accounts/api/multisig-revoke.ts 0.00% <0.00%> (ø)
... and 12 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@fmorency
Copy link
Copy Markdown
Contributor Author

Okay, I fixed the tests.

Alberto needs some love.

Copy link
Copy Markdown
Contributor

@stanleyjones stanleyjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!


export function useSaveWebauthnCredential() {
const [network] = useNetworkContext()
const { command: n } = useNetworkContext()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this was a little confusing... We were importing the query network just to use it's URL to create a command network? Why would we do that? Maybe we don't apply the IdStore module outside of this context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not sure why it was made the way it was.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end I had to revert this specific change because of #147

const queryNetwork = new Network(url, anonIdentity)
queryNetwork.apply([Ledger, IdStore, Account, Events, Base])
const cmdNetwork = new Network(url, identity)
cmdNetwork.apply([Ledger, IdStore, Account])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, there it is. Weird.

return [queryNetwork, cmdNetwork, eventNetworks] as [
Network,
Network,
Network[],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of me misses the chance to extend this to:

[
  Network,
  Network,
  Network[],
  Network[][],
]

Oh well. You win some, you lose some.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New design is still an improvement imo.

Comment on lines 8 to 14
setActiveId: (id: NetworkId) => void
updateNetwork: (id: NetworkId, n: NetworkParams) => void
getActiveNetwork: () => NetworkInfo
getLegacyNetworks: () => NetworkInfo[]
getNetworks: () => Map<NetworkId, NetworkInfo>
createNetwork: (n: NetworkInfo) => void
updateNetwork: (id: NetworkId, n: NetworkInfo) => void
deleteNetwork: (id: NetworkId) => void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up NetworkStore. Zustand pretends to be all "light weight" but you can actually get pretty gnarly pretty fast. I think we should've treated it more like a closed module and been more careful with the interface or even used something like useReducer so an action in one part of the app (changing a Network) could impact the state of a different part (the current identity). It's probably not too late, but it would be a substantial refactor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separation between Context and Store is a little weird at the moment.

@fmorency fmorency merged commit 17507f0 into liftedinit:main Sep 29, 2023
@fmorency fmorency deleted the design-update branch September 29, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants