Skip to content

Commit

Permalink
Simplify chain unwrapped mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Jul 24, 2023
1 parent 7cf3349 commit e0d19fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ export default {

staking: {
activeEra: {
unwrap: {
index: 700,
start: Date.now() - 5400000,
},
index: 700,
start: Date.now() - 5400000,
},
counterForValidators: 12,
counterForNominators: 20,
Expand Down
13 changes: 5 additions & 8 deletions packages/ui/src/mocks/helpers/asChainData.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { createType } from '@joystream/types'
import { isFunction, mapValues } from 'lodash'

export const asChainData = (data: any, key?: string | number): any => {
if (key === 'unwrap' && !isFunction(data)) {
const unwrappedValue = asChainData(data)
return () => unwrappedValue
}
import { mapValues } from 'lodash'

export const asChainData = (data: any): any => {
switch (Object.getPrototypeOf(data).constructor.name) {
case 'Object':
return mapValues(data, asChainData)
return withUnwrap(mapValues(data, asChainData))

case 'Array':
return data.map(asChainData)
Expand All @@ -24,3 +19,5 @@ export const asChainData = (data: any, key?: string | number): any => {
return data
}
}

const withUnwrap = (data: Record<any, any>) => Object.defineProperty(data, 'unwrap', { value: () => data })

0 comments on commit e0d19fb

Please sign in to comment.