Skip to content

Commit

Permalink
Simplify api mocks code
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Jul 3, 2023
1 parent f319bdd commit cbd32a7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/ui/src/mocks/providers/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export const MockApiProvider: FC<MockApiProps> = ({ children, chain }) => {
const api = {
_async: { chainMetadata: Promise.resolve({}) } as Api['_async'],
isConnected: true,
...asApi('consts', asApiConst),
...asApi('derive', asApiMethod),
...asApi('query', asApiMethod),
...asApi('rpc', asApiMethod, { chain: rpcChain }),
...asApi('tx', fromTxMock),
consts: asApi('consts', asApiConst),
derive: asApi('derive', asApiMethod),
query: asApi('query', asApiMethod),
rpc: asApi('rpc', asApiMethod, { chain: rpcChain }),
tx: asApi('tx', fromTxMock),
}

return watchForMissingProps(api, 'api') as Api
Expand All @@ -69,12 +69,10 @@ export const MockApiProvider: FC<MockApiProps> = ({ children, chain }) => {
common: MockApi[K] = {}
) {
const chainData: MockApi[K] = merge(common, chain?.[kind])
return {
[kind]: mapValues(chainData, (moduleParam, moduleName) => {
const module = mapValues(moduleParam, (value) => fn(value, moduleName))
return watchForMissingProps(module, `${kind}.${moduleName}`)
}),
} as Record<K, Api[K]>
return mapValues(chainData, (moduleData, moduleName) => {
const module = mapValues(moduleData, (value) => fn(value, moduleName))
return watchForMissingProps(module, `${kind}.${moduleName}`)
}) as Api[K]
}
}, [chain])

Expand Down

0 comments on commit cbd32a7

Please sign in to comment.