From e0d19fbc3959fa4569998d51a2f2f002f3ffb908 Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Mon, 24 Jul 2023 13:50:25 +0200 Subject: [PATCH] Simplify chain unwrapped mocks --- .../app/pages/Validators/ValidatorList.stories.tsx | 6 ++---- packages/ui/src/mocks/helpers/asChainData.ts | 13 +++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/ui/src/app/pages/Validators/ValidatorList.stories.tsx b/packages/ui/src/app/pages/Validators/ValidatorList.stories.tsx index e9822e0d05..782d608bc7 100644 --- a/packages/ui/src/app/pages/Validators/ValidatorList.stories.tsx +++ b/packages/ui/src/app/pages/Validators/ValidatorList.stories.tsx @@ -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, diff --git a/packages/ui/src/mocks/helpers/asChainData.ts b/packages/ui/src/mocks/helpers/asChainData.ts index 3babe651ec..a5bcc2780b 100644 --- a/packages/ui/src/mocks/helpers/asChainData.ts +++ b/packages/ui/src/mocks/helpers/asChainData.ts @@ -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) @@ -24,3 +19,5 @@ export const asChainData = (data: any, key?: string | number): any => { return data } } + +const withUnwrap = (data: Record) => Object.defineProperty(data, 'unwrap', { value: () => data })