Skip to content

Commit

Permalink
refactor(core): rename updateNetworkAlgod to updateAlgodConfig
Browse files Browse the repository at this point in the history
Rename method to better reflect its purpose of updating algod configuration
rather than the entire network.

- Rename `updateNetworkAlgod` to `updateAlgodConfig` in `WalletManager`
- Update method name in React/Vue/Solid adapters
- Update all test files to use new method name
- Update example projects to use renamed method
  • Loading branch information
drichar committed Jan 22, 2025
1 parent 7b20ac7 commit b8379be
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions examples/react-ts/src/NetworkControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function NetworkControls() {
networkConfig,
activeNetworkConfig,
setActiveNetwork,
updateNetworkAlgod,
updateAlgodConfig,
resetNetworkConfig
} = useNetwork()

Expand Down Expand Up @@ -46,7 +46,7 @@ export function NetworkControls() {
event.preventDefault()
try {
setError('')
updateNetworkAlgod(activeNetwork, {
updateAlgodConfig(activeNetwork, {
baseServer: configForm.baseServer,
port: configForm.port || undefined,
token: configForm.token
Expand Down
4 changes: 2 additions & 2 deletions examples/solid-ts/src/NetworkControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function NetworkControls() {
networkConfig,
activeNetworkConfig,
setActiveNetwork,
updateNetworkAlgod,
updateAlgodConfig,
resetNetworkConfig
} = useNetwork()

Expand Down Expand Up @@ -47,7 +47,7 @@ export function NetworkControls() {
try {
setError('')
const form = configForm()
updateNetworkAlgod(activeNetwork(), {
updateAlgodConfig(activeNetwork(), {
baseServer: form.baseServer,
port: form.port || undefined,
token: form.token
Expand Down
4 changes: 2 additions & 2 deletions examples/vue-ts/src/components/NetworkControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
networkConfig,
activeNetworkConfig,
setActiveNetwork,
updateNetworkAlgod,
updateAlgodConfig,
resetNetworkConfig
} = useNetwork()
Expand Down Expand Up @@ -42,7 +42,7 @@ const handleConfigSubmit = async (event: Event) => {
event.preventDefault()
try {
error.value = ''
updateNetworkAlgod(activeNetwork.value, {
updateAlgodConfig(activeNetwork.value, {
baseServer: configForm.baseServer,
port: configForm.port || undefined,
token: configForm.token
Expand Down
18 changes: 9 additions & 9 deletions packages/use-wallet-react/src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('useNetwork', () => {
mockWalletManager.networkConfig[NetworkId.TESTNET]
)
expect(typeof result.current.setActiveNetwork).toBe('function')
expect(typeof result.current.updateNetworkAlgod).toBe('function')
expect(typeof result.current.updateAlgodConfig).toBe('function')
})

it('updates activeNetwork and algodClient when setActiveNetwork is called', async () => {
Expand All @@ -169,13 +169,13 @@ describe('useNetwork', () => {
)
})

it('calls updateNetworkAlgod on the manager when updating network config', () => {
it('calls updateAlgodConfig on the manager when updating network config', () => {
const { result } = renderHook(() => useNetwork(), { wrapper })
const networkId = NetworkId.TESTNET
const config = { baseServer: 'https://new-server.com' }

act(() => {
result.current.updateNetworkAlgod(networkId, config)
result.current.updateAlgodConfig(networkId, config)
})

expect(mockWalletManager.networkConfig[networkId].algod.baseServer).toBe(config.baseServer)
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('useNetwork', () => {
const expectedClient = new algosdk.Algodv2('', 'https://new-server.com', '')

await act(async () => {
result.current.network.updateNetworkAlgod(networkId, config)
result.current.network.updateAlgodConfig(networkId, config)
})

expect(mockWalletManager.networkConfig[networkId].algod.baseServer).toBe(config.baseServer)
Expand All @@ -267,7 +267,7 @@ describe('useNetwork', () => {

// Modify the config
act(() => {
result.current.updateNetworkAlgod(NetworkId.TESTNET, {
result.current.updateAlgodConfig(NetworkId.TESTNET, {
token: 'custom-token',
baseServer: 'https://custom-server.com'
})
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('useNetwork', () => {
const expectedClient = new algosdk.Algodv2('', 'https://new-server.com', '')

await act(async () => {
result.current.network.updateNetworkAlgod(networkId, newConfig)
result.current.network.updateAlgodConfig(networkId, newConfig)
})

expect(mockWalletManager.networkConfig[networkId].algod.baseServer).toBe(newConfig.baseServer)
Expand All @@ -316,7 +316,7 @@ describe('useNetwork', () => {
const newConfig = { baseServer: 'https://new-server.com' }

await act(async () => {
networkResult.current.updateNetworkAlgod(networkId, newConfig)
networkResult.current.updateAlgodConfig(networkId, newConfig)
})

expect(mockWalletManager.networkConfig[networkId].algod.baseServer).toBe(newConfig.baseServer)
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('useNetwork', () => {

// Modify the config
await act(async () => {
networkResult.current.updateNetworkAlgod(networkId, {
networkResult.current.updateAlgodConfig(networkId, {
baseServer: 'https://modified-server.com'
})
})
Expand All @@ -369,7 +369,7 @@ describe('useNetwork', () => {

// Modify the config
await act(async () => {
networkResult.current.updateNetworkAlgod(networkId, {
networkResult.current.updateAlgodConfig(networkId, {
baseServer: 'https://modified-server.com'
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/use-wallet-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export const useNetwork = () => {
console.info(`[React] ✅ Active network set to ${networkId}.`)
}

const updateNetworkAlgod = (networkId: string, config: Partial<AlgodConfig>): void => {
manager.updateNetworkAlgod(networkId, config)
const updateAlgodConfig = (networkId: string, config: Partial<AlgodConfig>): void => {
manager.updateAlgodConfig(networkId, config)

// If this is the active network, update the algodClient
if (networkId === activeNetwork) {
Expand Down Expand Up @@ -113,7 +113,7 @@ export const useNetwork = () => {
networkConfig: manager.networkConfig,
activeNetworkConfig: manager.activeNetworkConfig,
setActiveNetwork,
updateNetworkAlgod,
updateAlgodConfig,
resetNetworkConfig
}
}
Expand Down
22 changes: 11 additions & 11 deletions packages/use-wallet-solid/src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ describe('useNetwork', () => {
})
})

it('provides updateNetworkAlgod function', () => {
it('provides updateAlgodConfig function', () => {
const TestComponent = () => {
const { updateNetworkAlgod } = useNetwork()
return <div data-testid="update-network-algod-type">{typeof updateNetworkAlgod}</div>
const { updateAlgodConfig } = useNetwork()
return <div data-testid="update-network-algod-type">{typeof updateAlgodConfig}</div>
}

render(() => (
Expand All @@ -397,7 +397,7 @@ describe('useNetwork', () => {
expect(screen.getByTestId('update-network-algod-type')).toHaveTextContent('function')
})

it('calls updateNetworkAlgod on the manager when updating network config', () => {
it('calls updateAlgodConfig on the manager when updating network config', () => {
const networkId = NetworkId.TESTNET
const config = {
token: 'new-token',
Expand All @@ -406,16 +406,16 @@ describe('useNetwork', () => {
}

const TestComponent = () => {
const { updateNetworkAlgod } = useNetwork()
const { updateAlgodConfig } = useNetwork()
return (
<button data-testid="update-btn" onClick={() => updateNetworkAlgod(networkId, config)}>
<button data-testid="update-btn" onClick={() => updateAlgodConfig(networkId, config)}>
Update
</button>
)
}

const mockUpdateNetworkAlgod = vi.fn()
mockWalletManager.updateNetworkAlgod = mockUpdateNetworkAlgod
const mockUpdateAlgodConfig = vi.fn()
mockWalletManager.updateAlgodConfig = mockUpdateAlgodConfig

render(() => (
<WalletProvider manager={mockWalletManager}>
Expand All @@ -426,14 +426,14 @@ describe('useNetwork', () => {
const updateButton = screen.getByTestId('update-btn')
fireEvent.click(updateButton)

expect(mockUpdateNetworkAlgod).toHaveBeenCalledWith(networkId, config)
expect(mockUpdateAlgodConfig).toHaveBeenCalledWith(networkId, config)
})

it('updates algodClient when modifying active network configuration', () => {
const newAlgodClient = new algosdk.Algodv2('', 'https://new-server.com', '')

const TestComponent = () => {
const { updateNetworkAlgod } = useNetwork()
const { updateAlgodConfig } = useNetwork()
const { algodClient } = useWallet()
return (
<div>
Expand All @@ -444,7 +444,7 @@ describe('useNetwork', () => {
mockWalletManager.networkConfig[NetworkId.TESTNET].algod.baseServer =
'https://new-server.com'
mockSetAlgodClient(newAlgodClient)
updateNetworkAlgod(NetworkId.TESTNET, {
updateAlgodConfig(NetworkId.TESTNET, {
baseServer: 'https://new-server.com'
})
}}
Expand Down
6 changes: 3 additions & 3 deletions packages/use-wallet-solid/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const useNetwork = () => {
console.info(`[Solid] ✅ Active network set to ${networkId}.`)
}

const updateNetworkAlgod = (networkId: string, config: Partial<AlgodConfig>): void => {
manager().updateNetworkAlgod(networkId, config)
const updateAlgodConfig = (networkId: string, config: Partial<AlgodConfig>): void => {
manager().updateAlgodConfig(networkId, config)

// If this is the active network, update the algodClient
if (networkId === activeNetwork()) {
Expand Down Expand Up @@ -115,7 +115,7 @@ export const useNetwork = () => {
networkConfig: () => manager().networkConfig,
activeNetworkConfig,
setActiveNetwork,
updateNetworkAlgod,
updateAlgodConfig,
resetNetworkConfig
}
}
Expand Down
28 changes: 14 additions & 14 deletions packages/use-wallet-vue/src/__tests__/useNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,26 @@ describe('useNetwork', () => {
expect(wrapper.get('[data-testid="activeNetwork"]').text()).toBe(NetworkId.MAINNET)
})

it('provides updateNetworkAlgod function', () => {
const { updateNetworkAlgod } = useNetwork()
expect(typeof updateNetworkAlgod).toBe('function')
it('provides updateAlgodConfig function', () => {
const { updateAlgodConfig } = useNetwork()
expect(typeof updateAlgodConfig).toBe('function')
})

it('calls updateNetworkAlgod on the manager when updating network config', () => {
it('calls updateAlgodConfig on the manager when updating network config', () => {
const networkId = NetworkId.TESTNET
const config = {
token: 'new-token',
baseServer: 'https://new-server.com',
port: '443'
}

const mockUpdateNetworkAlgod = vi.fn()
mockWalletManager.updateNetworkAlgod = mockUpdateNetworkAlgod
const mockUpdateAlgodConfig = vi.fn()
mockWalletManager.updateAlgodConfig = mockUpdateAlgodConfig

const { updateNetworkAlgod } = useNetwork()
updateNetworkAlgod(networkId, config)
const { updateAlgodConfig } = useNetwork()
updateAlgodConfig(networkId, config)

expect(mockUpdateNetworkAlgod).toHaveBeenCalledWith(networkId, config)
expect(mockUpdateAlgodConfig).toHaveBeenCalledWith(networkId, config)
})

it('provides activeNetworkConfig through useNetwork', async () => {
Expand Down Expand Up @@ -249,17 +249,17 @@ describe('useNetwork', () => {
<div data-testid="active-network-config">{{ stringifiedConfig }}</div>
`,
setup() {
const { activeNetworkConfig, updateNetworkAlgod } = useNetwork()
const { activeNetworkConfig, updateAlgodConfig } = useNetwork()
const stringifiedConfig = computed(() => JSON.stringify(activeNetworkConfig.value))
return { stringifiedConfig, updateNetworkAlgod }
return { stringifiedConfig, updateAlgodConfig }
}
}

const wrapper = mount(TestComponent)
const networkId = NetworkId.TESTNET
const newConfig = { baseServer: 'https://new-server.com' }

mockWalletManager.updateNetworkAlgod = (id: string, config: Partial<AlgodConfig>) => {
mockWalletManager.updateAlgodConfig = (id: string, config: Partial<AlgodConfig>) => {
mockWalletManager.networkConfig[id] = {
...mockWalletManager.networkConfig[id],
algod: {
Expand All @@ -270,8 +270,8 @@ describe('useNetwork', () => {
mockStore.setState((state) => ({ ...state }))
}

const { updateNetworkAlgod } = useNetwork()
updateNetworkAlgod(networkId, newConfig)
const { updateAlgodConfig } = useNetwork()
updateAlgodConfig(networkId, newConfig)
await nextTick()

const actual = JSON.parse(wrapper.get('[data-testid="active-network-config"]').text())
Expand Down
6 changes: 3 additions & 3 deletions packages/use-wallet-vue/src/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export function useNetwork() {
console.info(`[Vue] ✅ Active network set to ${networkId}.`)
}

const updateNetworkAlgod = (networkId: string, config: Partial<AlgodConfig>): void => {
manager.updateNetworkAlgod(networkId, config)
const updateAlgodConfig = (networkId: string, config: Partial<AlgodConfig>): void => {
manager.updateAlgodConfig(networkId, config)
manager.store.setState((state) => ({ ...state }))

// If this is the active network, update the algodClient
Expand Down Expand Up @@ -82,7 +82,7 @@ export function useNetwork() {
networkConfig: manager.networkConfig,
activeNetworkConfig,
setActiveNetwork,
updateNetworkAlgod,
updateAlgodConfig,
resetNetworkConfig
}
}
Loading

0 comments on commit b8379be

Please sign in to comment.