Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Refactor: CType Utility and Split Metadata and Schema #231

Merged
merged 39 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3b022c8
refactor: added ctype utils to the demo client
Dudleyneedham Oct 10, 2019
9a6a11b
refactor: added ctype utils to the demo client
Dudleyneedham Oct 10, 2019
b91433d
refactor: trying to get the ctype utils to work
Dudleyneedham Oct 11, 2019
a024bdd
refactor: trying to get the ctype utils to work
Dudleyneedham Oct 11, 2019
950cc3e
refactor: trying to get the ctype utils to work
Dudleyneedham Oct 11, 2019
4547c8c
refactor: trying to get the ctype utils to work
Dudleyneedham Oct 14, 2019
bf55a1a
refactor: cleaning up types
Dudleyneedham Oct 14, 2019
aef0ad9
refactor: added the test unable to run them changed according to review
Dudleyneedham Oct 14, 2019
0ab92b1
refactor: cleaned up file structuring and pathing
Dudleyneedham Oct 15, 2019
b2b3816
refactor: cleaned up file structuring and pathing
Dudleyneedham Oct 15, 2019
c42ab22
refactor: working on demo client refactor
Dudleyneedham Nov 5, 2019
02113f5
refactor: changes to the demo client
Dudleyneedham Nov 5, 2019
bd867f6
refactor: changed ctype utils and changes into spliting the metadata
Dudleyneedham Nov 7, 2019
82a58b5
refactor: changed to new type of metadata
Dudleyneedham Nov 8, 2019
f4a390e
refactor: changed to ctype get propertytitle
Dudleyneedham Nov 11, 2019
f627122
refactor: cleaned up file structuring and pathing
Dudleyneedham Oct 15, 2019
6446bc9
refactor: changed ctype utils and changes into spliting the metadata
Dudleyneedham Nov 7, 2019
78342ff
refactor: changed to new type of metadata
Dudleyneedham Nov 8, 2019
e708c23
refactor: changed to ctype get propertytitle
Dudleyneedham Nov 11, 2019
3f2d9dc
chore: merge sdk compatibility
Dec 20, 2019
a7067e7
chore: merge sdk compatibility
Dec 20, 2019
070c76c
feat: split metadata from ctype
Dec 23, 2019
064c3e0
Merge branch 'develop' into dn-demo-200-ctype-utils-refac-objec
LeonFLK Jan 8, 2020
83036e1
fix: devtools split metadatafix
Jan 8, 2020
9159376
fix: devtools split metadatafix
Jan 8, 2020
f2f96d0
chore: merge resolved conflicts
Jan 8, 2020
32576e8
fix: removed devtools unnecessary messages
Jan 8, 2020
77f5499
feat: linting requested changes removing deprecated class
Jan 9, 2020
c38017b
feat: getCtypePropertyTitle added to utils
Jan 9, 2020
c457137
chore: merge develop
Jan 9, 2020
367560a
fix: test claims compatibility
Jan 10, 2020
14ab84b
chore: bump skd in lockfile and compatibility
Jan 15, 2020
a9deaf6
chore: bump sdk to 0.17.0 with generic version
Jan 15, 2020
08b383a
fix: add metadata to ctypedetailview
Jan 15, 2020
e4b6141
fix: reverted removal of getClaimInputModel
Jan 16, 2020
630400e
fix: accessible metadata.title.default
Jan 16, 2020
c4841b8
fix: namingconvention for Ictypewithmetadata interface
Jan 16, 2020
f519421
test: fix CTypeUtils tests
tjwelde Jan 17, 2020
d26fef2
style: fix prettier warnings
tjwelde Jan 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/AttestationStatus/AttestationStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AttestationStatus extends React.Component<Props, State> {
})
if (isAttestedClaim(attestation)) {
PersistentStore.store.dispatch(
Claims.Store.revokeAttestation(attestation.request.hash)
Claims.Store.revokeAttestation(attestation.request.rootHash)
)
} else {
PersistentStore.store.dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AttestedClaimVerificationView extends React.Component<Props, State> {
inline={true}
/>
<CTypePresentation
cTypeHash={attestedClaim.request.claim.cType}
cTypeHash={attestedClaim.request.claim.cTypeHash}
interactive={true}
linked={true}
inline={true}
Expand Down
10 changes: 5 additions & 5 deletions src/components/CTypePresentation/CTypePresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SubmitLegitimationsProps } from '../../containers/Tasks/SubmitLegitimat
import CTypeRepository from '../../services/CtypeRepository'
import * as UiState from '../../state/ducks/UiState'
import PersistentStore from '../../state/PersistentStore'
import { ICType } from '../../types/Ctype'
import { CTypeMetadata, ICType } from '../../types/Ctype'
import SelectAction, { Action } from '../SelectAction/SelectAction'

import './CTypePresentation.scss'
Expand All @@ -30,7 +30,7 @@ type Props = RouteComponentProps<{}> & {
}

type State = {
cType?: ICType
cType?: CTypeMetadata
}

const DEFAULT_SIZE = 24
Expand Down Expand Up @@ -91,7 +91,7 @@ class CTypePresentation extends React.Component<Props, State> {
size={size || DEFAULT_SIZE}
theme="polkadot"
/>
{this.getLabel(cType.cType.metadata.title.default)}
{this.getLabel(cType.cType.schema.$id)}
tjwelde marked this conversation as resolved.
Show resolved Hide resolved
tjwelde marked this conversation as resolved.
Show resolved Hide resolved
</>
)}
{!!actions.length && (
Expand Down Expand Up @@ -121,7 +121,7 @@ class CTypePresentation extends React.Component<Props, State> {
private async setCType() {
const { cTypeHash } = this.props

CTypeRepository.findByHash(cTypeHash).then((_cType: ICType) => {
CTypeRepository.findByHash(cTypeHash).then((_cType: CTypeMetadata) => {
this.setState({ cType: _cType })
})
}
Expand Down Expand Up @@ -188,7 +188,7 @@ class CTypePresentation extends React.Component<Props, State> {
UiState.Store.updateCurrentTaskAction({
objective: sdk.MessageBodyType.SUBMIT_LEGITIMATIONS,
props: {
claim: { cType: cTypeHash },
claim: { cTypeHash: cTypeHash },
} as SubmitLegitimationsProps,
})
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClaimDetailView/ClaimDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ClaimDetailView extends Component<Props, State> {
<label>Ctype</label>
<div>
<CTypePresentation
cTypeHash={claim.cType}
cTypeHash={claim.cTypeHash}
linked={true}
interactive={true}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/components/CtypeDetailView/CtypeDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import { Link } from 'react-router-dom'
import CTypeRepository from '../../services/CtypeRepository'

import { ICType } from '../../types/Ctype'
import { ICType, CTypeMetadata } from '../../types/Ctype'
import Code from '../Code/Code'
import ContactPresentation from '../ContactPresentation/ContactPresentation'
import CTypePresentation from '../CTypePresentation/CTypePresentation'
Expand All @@ -14,7 +14,7 @@ type Props = {
}

type State = {
cType?: ICType
cType?: CTypeMetadata
}

class CtypeDetailView extends React.Component<Props, State> {
Expand All @@ -25,7 +25,7 @@ class CtypeDetailView extends React.Component<Props, State> {

public componentDidMount() {
const { cTypeHash } = this.props
CTypeRepository.findByHash(cTypeHash).then((_cType: ICType) => {
CTypeRepository.findByHash(cTypeHash).then((_cType: CTypeMetadata) => {
this.setState({ cType: _cType })
})
}
Expand All @@ -41,13 +41,13 @@ class CtypeDetailView extends React.Component<Props, State> {
<div className="attributes">
<div>
<label>Title</label>
<div>{cType.cType.metadata.title.default}</div>
<div>{cType.cType.schema.$id}</div>
tjwelde marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div>
<label>Author</label>
<div>
<ContactPresentation
address={cType.metaData.author}
address={cType.cType.owner!}
interactive={true}
/>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/components/CtypeListView/CtypeListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { Link, RouteComponentProps, withRouter } from 'react-router-dom'
import CTypeRepository from '../../services/CtypeRepository'
import * as CTypes from '../../state/ducks/CTypes'
import { State as ReduxState } from '../../state/PersistentStore'
import { ICType } from '../../types/Ctype'
import { ICType, CTypeMetadata } from '../../types/Ctype'
import ContactPresentation from '../ContactPresentation/ContactPresentation'
import CTypePresentation from '../CTypePresentation/CTypePresentation'

import './CtypeListView.scss'

type Props = RouteComponentProps<{}> & {
onRequestLegitimation: (cType: ICType) => void
onRequestLegitimation: (cType: CTypeMetadata) => void
// mapStateToProps
cTypes?: ICType[]
cTypes?: CTypeMetadata[]
}

type State = {
Expand Down Expand Up @@ -64,7 +64,7 @@ class CtypeListView extends React.Component<Props, State> {
right={true}
/>
<ContactPresentation
address={cType.metaData.author}
address={cType.cType.owner!}
tjwelde marked this conversation as resolved.
Show resolved Hide resolved
interactive={true}
right={true}
/>
Expand All @@ -78,7 +78,7 @@ class CtypeListView extends React.Component<Props, State> {
</td>
<td className="author">
<ContactPresentation
address={cType.metaData.author}
address={cType.cType.owner!}
interactive={true}
right={true}
/>
Expand Down
17 changes: 9 additions & 8 deletions src/components/DevTools/DevTools.attestations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import * as Attestations from '../../state/ducks/Attestations'
import { MyDelegation } from '../../state/ducks/Delegations'
import PersistentStore from '../../state/PersistentStore'
import { MyIdentity } from '../../types/Contact'
import { ICType } from '../../types/Ctype'
import { ICType, CTypeMetadata } from '../../types/Ctype'
import { BsClaim, BsClaimsPool, BsClaimsPoolElement } from './DevTools.claims'
import { BsCType } from './DevTools.ctypes'
import { BsDelegation, BsDelegationsPool } from './DevTools.delegations'
import { BsIdentitiesPool, BsIdentity } from './DevTools.wallet'

import attestationsPool from './data/attestations.json'
import { IPartialClaim } from '@kiltprotocol/sdk-js'

type UpdateCallback = (bsAttestationKey: keyof BsAttestationsPool) => void

Expand Down Expand Up @@ -179,11 +180,11 @@ class BsAttestation {
)
}

return new sdk.RequestForAttestation(
return sdk.RequestForAttestation.fromClaimAndIdentity(
claimToAttest.claim,
_legitimations,
claimerIdentity.identity,
delegation ? delegation.id : undefined
_legitimations,
delegation ? delegation.id : null
)
}

Expand Down Expand Up @@ -220,7 +221,7 @@ class BsAttestation {
// store attestation locally
AttestationService.saveInStore({
attestation: attestedClaim.attestation,
cTypeHash: attestedClaim.request.claim.cType,
cTypeHash: attestedClaim.request.claim.cTypeHash,
claimerAddress: claimerIdentity.identity.address,
claimerAlias: claimerIdentity.metaData.name,
created: Date.now(),
Expand All @@ -240,10 +241,10 @@ class BsAttestation {
const { attesterKey } = attest

const attesterIdentity: MyIdentity = await BsIdentity.getByKey(attesterKey)
const cType: ICType = await BsCType.getByKey(bsClaim.cTypeKey)
const cType: CTypeMetadata = await BsCType.getByKey(bsClaim.cTypeKey)

const partialClaim = {
cType: cType.cType.hash as string,
const partialClaim: IPartialClaim = {
cTypeHash: cType.cType.hash as string,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need the as string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not part of this ticket / PR

contents: bsClaim.data,
owner: claimerIdentity.identity.address,
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/DevTools/DevTools.claims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class BsClaim {
): Promise<void | sdk.Claim> {
const identity = await BsIdentity.getByKey(BS_claimData.claimerKey)
const cType = (await BsCType.getByKey(BS_claimData.cTypeKey)).cType
const claim = new sdk.Claim(
sdk.CType.fromObject(cType),
const claim = sdk.Claim.fromCTypeAndClaimContents(
sdk.CType.fromCType(cType),
BS_claimData.data,
identity.identity
identity.identity.address
)

PersistentStore.store.dispatch(
Expand Down
59 changes: 34 additions & 25 deletions src/components/DevTools/DevTools.ctypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as sdk from '@kiltprotocol/sdk-js'
import BlockchainService from '../../services/BlockchainService'
import CTypeRepository from '../../services/CtypeRepository'
import errorService from '../../services/ErrorService'
import { notifySuccess } from '../../services/FeedbackService'
import { ICType } from '../../types/Ctype'
import { notifySuccess, notifyError } from '../../services/FeedbackService'
import { CTypeMetadata } from '../../types/Ctype'
import { BsIdentity } from './DevTools.wallet'

import cTypesPool from './data/cTypes.json'
Expand All @@ -13,6 +13,7 @@ type UpdateCallback = (bsCTypeKey: keyof BsCTypesPool) => void

interface BsCTypesPoolElement extends sdk.ICType {
owner: string
metadata: sdk.ICTypeMetadata['metadata']
}

type BsCTypesPool = {
Expand All @@ -27,34 +28,38 @@ class BsCType {
const ownerIdentity = (await BsIdentity.getByKey(bsCTypeData.owner))
.identity

const cType = sdk.CType.fromObject({
...bsCTypeData,
owner: ownerIdentity.address,
const cType = sdk.CType.fromCType({
schema: bsCTypeData.schema,
hash: bsCTypeData.hash,
owner: ownerIdentity.address
})

return cType
cType
.store(ownerIdentity)
.then((value: any) => {
const cTypeWrapper: ICType = {
.catch(error => {
errorService.log({
error,
message: 'Could not submit CTYPE to the Blockchain',
origin: 'CType.store()',
})
}).then(() => {
const cTypeWrapper: CTypeMetadata = {
cType,
metaData: {
author: ownerIdentity.address,
metadata: bsCTypeData.metadata,
ctypeHash: cType.hash
},
}
// TODO: add onrejected when sdk provides error handling
return CTypeRepository.register(cTypeWrapper)
})
.then(() => {
notifySuccess(
`CTYPE ${cType.metadata.title.default} successfully created.`
)
})
.catch(error => {
errorService.log({
error,
message: 'Could not submit CTYPE',
origin: 'CTypeCreate.submit()',
return CTypeRepository.register(cTypeWrapper).then(() => {
notifySuccess(`CTYPE ${cType.schema.$id} successfully created.`)
})
.catch(error => {
errorService.log({
error,
message: 'Could not submit CTYPE to the Registry',
origin: 'CTypeRepository.register()',
})
})
})
}

Expand All @@ -71,21 +76,25 @@ class BsCType {
return requests
}

public static async getByHash(hash: sdk.ICType['hash']): Promise<ICType> {
public static async getByHash(
hash: sdk.ICType['hash']
): Promise<CTypeMetadata> {
const cType = await CTypeRepository.findByHash(hash)
if (cType) {
return cType
}
throw new Error(`Could not find cType with hash '${hash}'`)
}

public static async get(bsCType: BsCTypesPoolElement): Promise<ICType> {
public static async get(
bsCType: BsCTypesPoolElement
): Promise<CTypeMetadata> {
return BsCType.getByHash(bsCType.hash)
}

public static async getByKey(
bsCTypeKey: keyof BsCTypesPool
): Promise<ICType> {
): Promise<CTypeMetadata> {
const { hash } = BsCType.pool[bsCTypeKey]
return BsCType.getByHash(hash)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/DevTools/DevTools.delegations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Delegations from '../../state/ducks/Delegations'
import { DelegationType, MyDelegation } from '../../state/ducks/Delegations'
import PersistentStore from '../../state/PersistentStore'
import { MyIdentity } from '../../types/Contact'
import { ICType } from '../../types/Ctype'
import { CTypeMetadata } from '../../types/Ctype'
import { BsCType, BsCTypesPool } from './DevTools.ctypes'
import { BsIdentitiesPool, BsIdentity } from './DevTools.wallet'

Expand Down Expand Up @@ -172,7 +172,7 @@ class BsDelegation {
}
const ownerIdentity: MyIdentity = await BsIdentity.getByKey(ownerKey)
await BsIdentity.selectIdentity(ownerIdentity)
const cType: ICType = await BsCType.getByKey(cTypeKey)
const cType: CTypeMetadata = await BsCType.getByKey(cTypeKey)

if (updateCallback) {
updateCallback(bsDelegationKey)
Expand Down
12 changes: 6 additions & 6 deletions src/components/Modal/SelectCTypesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Select from 'react-select'
import CTypeRepository from '../../services/CtypeRepository'

import ErrorService from '../../services/ErrorService'
import { ICType } from '../../types/Ctype'
import { CTypeMetadata } from '../../types/Ctype'
import SelectCTypes from '../SelectCTypes/SelectCTypes'
import Modal, { ModalType } from './Modal'

Expand All @@ -17,13 +17,13 @@ type Props = {
showOnInit?: boolean

onCancel?: () => void
onConfirm: (selectedCTypes: ICType[]) => void
onConfirm: (selectedCTypes: CTypeMetadata[]) => void
}

type State = {
cTypes?: ICType[]
cTypes?: CTypeMetadata[]
isSelectCTypesOpen: boolean
selectedCTypes: ICType[]
selectedCTypes: CTypeMetadata[]
}

class SelectCTypesModal extends React.Component<Props, State> {
Expand Down Expand Up @@ -85,7 +85,7 @@ class SelectCTypesModal extends React.Component<Props, State> {
>
<div>
<SelectCTypes
cTypes={cTypes as ICType[]}
cTypes={cTypes as CTypeMetadata[]}
name={name as string}
isMulti={isMulti}
closeMenuOnSelect={closeMenuOnSelect}
Expand All @@ -111,7 +111,7 @@ class SelectCTypesModal extends React.Component<Props, State> {
}
}

private onSelectCTypes(selectedCTypes: ICType[]) {
private onSelectCTypes(selectedCTypes: CTypeMetadata[]) {
this.setState({ selectedCTypes })
}

Expand Down
Loading