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

Commit

Permalink
feat: added did register to dashboard (#324)
Browse files Browse the repository at this point in the history
* fix: added metadata to now add by default the contacts to fav

* feat: adding creation and deletion did on dashboard

* feat: updated wallet store to handle select identity by filter iden stre

* feat: updated all store to handle new select store

* feat: removed the did delete

* Revert "fix: added metadata to now add by default the contacts to fav"

This reverts commit ebf28c8.

* feat: removed an unused conditional that might have unintended effects
  • Loading branch information
Dudleyneedham authored Feb 2, 2021
1 parent 42a2d91 commit fa7bb2d
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/components/ContactPresentation/ContactPresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class ContactPresentation extends React.Component<Props, State> {
metaData: {
...metaData,
addedAt: Date.now(),
addedBy: selectedIdentity.identity.address,
addedBy: selectedIdentity?.identity.address,
},
publicIdentity,
}
Expand Down
65 changes: 51 additions & 14 deletions src/components/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from 'react'
import { connect, MapStateToProps } from 'react-redux'
import { Link } from 'react-router-dom'
import DidService from '../../services/DidService'
import FeedbackService, {
notifySuccess,
notifyError,
safeDelete,
} from '../../services/FeedbackService'
import { IMyIdentity } from '../../types/Contact'
import Balance from '../../containers/Balance/Balance'

import * as Wallet from '../../state/ducks/Wallet'
Expand All @@ -11,24 +18,54 @@ import IdentityView from '../IdentityView/IdentityView'
import './Dashboard.scss'

type StateProps = {
selectedIdentity: Wallet.Entry
selectedIdentity?: Wallet.Entry
}

type Props = StateProps

const Dashboard: React.FC<Props> = ({ selectedIdentity }): JSX.Element => (
<section className="Dashboard">
<h1>
<div>My Dashboard</div>
<ContactPresentation address={selectedIdentity.identity.address} inline />
</h1>
<IdentityView myIdentity={selectedIdentity} selected />
<div className="actions">
<Link to="/wallet">Manage Identities</Link>
</div>
<Balance myIdentity={selectedIdentity} />
</section>
)
const Dashboard: React.FC<Props> = ({ selectedIdentity }) => {
if (!selectedIdentity) {
return null
}

const createDid = (myIdentity: IMyIdentity): void => {
const blockUi = FeedbackService.addBlockUi({
headline: `Generating DID for '${myIdentity.metaData.name}'`,
})
DidService.createDid(myIdentity) // TODO: add document reference
.then(() => {
notifySuccess(
`DID for '${myIdentity.metaData.name}' successfully generated`
)
blockUi.remove()
})
.catch(err => {
notifyError(err)
blockUi.remove()
})
}

return (
<section className="Dashboard">
<h1>
<div>My Dashboard</div>
<ContactPresentation
address={selectedIdentity.identity.address}
inline
/>
</h1>
<IdentityView
myIdentity={selectedIdentity}
selected
onCreateDid={createDid}
/>
<div className="actions">
<Link to="/wallet">Manage Identities</Link>
</div>
<Balance myIdentity={selectedIdentity} />
</section>
)
}

const mapStateToProps: MapStateToProps<StateProps, {}, ReduxState> = state => ({
selectedIdentity: Wallet.getSelectedIdentity(state),
Expand Down
6 changes: 5 additions & 1 deletion src/components/DelegationDetailView/DelegationDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import DelegationNode, {
import './DelegationDetailView.scss'

type StateProps = {
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type OwnProps = {
Expand Down Expand Up @@ -86,6 +86,10 @@ const DelegationDetailView: React.FunctionComponent<Props> = ({
})
}, [delegationId])

if (!selectedIdentity) {
return null
}

return (
<section className="DelegationDetailView">
<h1>{isPCR ? 'PCR view' : 'Delegation tree'}</h1>
Expand Down
4 changes: 3 additions & 1 deletion src/components/DevTools/DevTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class DevTools extends React.Component<Props> {
{ label: 'With messages', with: true },
]

const selectedIdentity: IMyIdentity = Wallet.getSelectedIdentity(
const selectedIdentity:
| IMyIdentity
| undefined = Wallet.getSelectedIdentity(
persistentStoreInstance.store.getState()
)

Expand Down
11 changes: 8 additions & 3 deletions src/components/DevTools/DevTools.wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ class BsIdentity {
phrase: string,
alias: string
): Promise<void | IMyIdentity> {
const selectedIdentity: IMyIdentity = Wallet.getSelectedIdentity(
const selectedIdentity:
| IMyIdentity
| undefined = Wallet.getSelectedIdentity(
persistentStoreInstance.store.getState()
)

return new Promise(resolve => {
BalanceUtilities.makeTransfer(
return new Promise((resolve, reject) => {
if (!selectedIdentity) {
return reject(new Error('No Identity selected'))
}
return BalanceUtilities.makeTransfer(
selectedIdentity,
identity.address,
ENDOWMENT,
Expand Down
2 changes: 1 addition & 1 deletion src/components/IdentityView/IdentityView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class IdentityView extends React.Component<Props, State> {
addedAt: Date.now(),
addedBy: Wallet.getSelectedIdentity(
persistentStoreInstance.store.getState()
).identity.address,
)?.identity.address,
},
publicIdentity,
} as IContact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import './MyDelegationsInviteModal.scss'

type StateProps = {
myDelegations: IMyDelegation[]
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type OwnProps = {
Expand Down Expand Up @@ -299,7 +299,9 @@ class MyDelegationsInviteModal extends React.Component<Props, State> {
): void {
const { selectedIdentity } = this.props
const { metaData } = delegation

if (!selectedIdentity) {
throw new Error('No selected Identity')
}
const delegationData = this.getDelegationData(receiver, delegation)

const messageBody: IRequestAcceptDelegation = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SelectAction, { Action } from '../SelectAction/SelectAction'

type StateProps = {
debugMode: boolean
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type OwnProps = {
Expand Down Expand Up @@ -120,6 +120,11 @@ class SelectDelegationAction extends React.Component<Props> {

private getQRCodeAction(): Action | undefined {
const { delegation, debugMode, onQRCode, selectedIdentity } = this.props

if (!selectedIdentity) {
throw new Error('No selected Identity')
}

if (!delegation || !onQRCode) {
return undefined
}
Expand Down
4 changes: 0 additions & 4 deletions src/components/Utilities/Utilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import { connect, MapStateToProps } from 'react-redux'
import sdkPackage from '@kiltprotocol/sdk-js/package.json'

import * as UiState from '../../state/ducks/UiState'
import * as Wallet from '../../state/ducks/Wallet'
import { State as ReduxState } from '../../state/PersistentStore'
import ChainStats from '../ChainStats/ChainStats'
import TestUserFeedback from '../TestUserFeedback/TestUserFeedback'
import DevTools from '../DevTools/DevTools'
import ClientVersionHelper from '../../services/ClientVersionHelper'
import { safeDestructiveAction } from '../../services/FeedbackService'
import { IMyIdentity } from '../../types/Contact'
import './Utilities.scss'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const clientPackage = require('../../../package.json')

type StateProps = {
debugMode: boolean
selectedIdentity: IMyIdentity
}

type DispatchProps = {
Expand Down Expand Up @@ -96,7 +93,6 @@ class Utilities extends React.Component<Props> {

const mapStateToProps: MapStateToProps<StateProps, {}, ReduxState> = state => ({
debugMode: UiState.getDebugMode(state),
selectedIdentity: Wallet.getSelectedIdentity(state),
})

const mapDispatchToProps: DispatchProps = {
Expand Down
4 changes: 4 additions & 0 deletions src/containers/Balance/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class Balance extends React.Component<Props, State> {
persistentStoreInstance.store.getState()
)

if (!selectedIdentity) {
throw new Error('No selected Error')
}

// the identity of this component might not be the currently selected one
// so we need to inform the user in this case
if (myIdentity.identity.address !== selectedIdentity.identity.address) {
Expand Down
6 changes: 5 additions & 1 deletion src/containers/ClaimView/ClaimView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { RequestTermsProps } from '../Tasks/RequestTerms/RequestTerms'

type StateProps = {
claimEntries: Claims.Entry[]
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type DispatchProps = {
Expand Down Expand Up @@ -86,6 +86,10 @@ class ClaimView extends React.Component<Props, State> {

public componentDidUpdate(prevProps: Props): void {
const { selectedIdentity } = this.props
if (!selectedIdentity || !prevProps.selectedIdentity) {
throw new Error('No selected Identity')
}

if (
prevProps.selectedIdentity.identity.address !==
selectedIdentity.identity.address
Expand Down
7 changes: 6 additions & 1 deletion src/containers/DelegationsView/DelegationsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import './DelegationsView.scss'

type StateProps = {
delegationEntries: IMyDelegation[]
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type DispatchProps = {
Expand Down Expand Up @@ -89,6 +89,11 @@ class DelegationsView extends React.Component<Props, State> {

public componentDidUpdate(prevProps: Props): void {
const { delegationEntries, isPCR, selectedIdentity } = this.props

if (!selectedIdentity || !prevProps.selectedIdentity) {
throw new Error('No selected Identity')
}

if (
prevProps.selectedIdentity.identity.address !==
selectedIdentity.identity.address
Expand Down
3 changes: 0 additions & 3 deletions src/containers/MyQuotesList/MyQuotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as Quotes from '../../state/ducks/Quotes'
import * as Wallet from '../../state/ducks/Wallet'
import Code from '../../components/Code/Code'
import './MyQuotesList.scss'
import { IMyIdentity } from '../../types/Contact'

type DispatchProps = {
removeQuote: (claimId: Quotes.Entry['quoteId']) => void
Expand All @@ -16,7 +15,6 @@ type DispatchProps = {
type OwnProps = {}

type StateProps = {
selectedIdentity: IMyIdentity
quoteEntries: Quotes.Entry[]
}

Expand Down Expand Up @@ -94,7 +92,6 @@ const mapStateToProps: MapStateToProps<
OwnProps,
ReduxState
> = state => ({
selectedIdentity: Wallet.getSelectedIdentity(state),
quoteEntries: Quotes.getAllMyQuotes(state),
})

Expand Down
4 changes: 0 additions & 4 deletions src/containers/QuoteView/QuoteView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import { connect, MapStateToProps } from 'react-redux'
import { RouteComponentProps, withRouter } from 'react-router-dom'
import { IPartialClaim, IQuote } from '@kiltprotocol/sdk-js'
import { State as ReduxState } from '../../state/PersistentStore'
import { IMyIdentity } from '../../types/Contact'
import * as Wallet from '../../state/ducks/Wallet'
import * as Quotes from '../../state/ducks/Quotes'
import QuoteCreate from '../QuoteCreate/QuoteCreate'
import Code from '../../components/Code/Code'

type StateProps = {
selectedIdentity: IMyIdentity
quoteEntries?: Quotes.Entry[]
}

Expand Down Expand Up @@ -111,7 +108,6 @@ const mapStateToProps: MapStateToProps<
OwnProps,
ReduxState
> = state => ({
selectedIdentity: Wallet.getSelectedIdentity(state),
quoteEntries: Quotes.getAllMyQuotes(state),
})

Expand Down
6 changes: 5 additions & 1 deletion src/containers/Tasks/AcceptDelegation/AcceptDelegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import DelegationsService from '../../../services/DelegationsService'
import './AcceptDelegation.scss'

type StateProps = {
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type OwnProps = {
Expand Down Expand Up @@ -98,6 +98,10 @@ class AcceptDelegation extends React.Component<Props, State> {
const { selectedIdentity } = this.props
const { account, id, parentId, permissions } = delegationData

if (!selectedIdentity) {
throw new Error('No selected Identity')
}

const rootNode: IDelegationRootNode | null = await DelegationsService.findRootNode(
parentId
)
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Tasks/AttestClaim/AttestClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class AttestClaim extends React.Component<Props, State> {
headline: 'Writing attestation to chain',
})

const selectedIdentity: Identity = Wallet.getSelectedIdentity(
const selectedIdentity = Wallet.getSelectedIdentity(
persistentStoreInstance.store.getState()
).identity
)?.identity

if (!selectedIdentity) {
throw new Error('No identity selected')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type RequestAcceptDelegationProps = {
type StateProps = {
debugMode: boolean
myDelegations: IMyDelegation[]
selectedIdentity: IMyIdentity
selectedIdentity?: IMyIdentity
}

type Props = RequestAcceptDelegationProps & StateProps
Expand Down Expand Up @@ -155,6 +155,10 @@ class RequestAcceptDelegation extends React.Component<Props, State> {
const { selectedIdentity } = this.props
const { metaData } = delegation

if (!selectedIdentity) {
throw new Error('No selected Identity')
}

const delegationData = this.getDelegationData(receiverAddress, delegation)

const messageBody: IRequestAcceptDelegation = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ class RequestAttestation extends React.Component<Props, State> {
} = this.props
const { savedClaimEntry } = this.state

const selectedIdentity: Identity = Wallet.getSelectedIdentity(
const selectedIdentity = Wallet.getSelectedIdentity(
persistentStoreInstance.store.getState()
).identity
)?.identity

if (!selectedIdentity) {
throw new Error('No identity selected')
throw new Error('No selected Identity')
}

if (savedClaimEntry) {
Expand Down
Loading

0 comments on commit fa7bb2d

Please sign in to comment.