Skip to content

Commit

Permalink
feat: return network being edited
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron committed Oct 16, 2024
1 parent 9049bd7 commit 888bd00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion packages/app/src/systems/Network/hooks/useNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,27 @@ const selectors = {
selectedNetwork: (state: NetworksMachineState) => {
return state.context?.network || undefined;
},
editingNetwork: (id: string) => (state: NetworksMachineState) => {
return (
(id && state.context?.networks?.find((n) => n.id === id)) || undefined
);
},
};

export function useNetworks() {
const overlay = useOverlay();
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const selectedNetworkId = (overlay.metadata as any)?.id;
const networks = store.useSelector(Services.networks, selectors.networks);
const network = store.useSelector(Services.networks, selectors.network);
const isLoading = store.useSelector(Services.networks, selectors.isLoading);
const editingNetwork = store.useSelector(
Services.networks,
useMemo(
() => selectors.editingNetwork(selectedNetworkId),
[selectedNetworkId]
)
);
const selectedNetworkState = store.useSelector(
Services.networks,
selectors.selectedNetwork
Expand Down Expand Up @@ -68,7 +82,7 @@ export function useNetworks() {
function goToUpdate(id?: string) {
if (!id) return;
store.editNetwork({ id });
store.openNetworkUpdate();
store.openNetworkUpdate({ id });
}

return {
Expand All @@ -84,6 +98,7 @@ export function useNetworks() {
},
isLoading,
selectedNetwork,
editingNetwork,
network,
networks,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/systems/Overlay/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export function overlayEvents(store: Store) {
input: { modal: 'networks.add' },
});
},
openNetworkUpdate() {
openNetworkUpdate(params: { id: string }) {
store.send(Services.overlay, {
type: 'OPEN',
input: { modal: 'networks.update' },
input: { modal: 'networks.update', params },
});
},
openTransactionApprove() {
Expand Down

0 comments on commit 888bd00

Please sign in to comment.