Skip to content

Commit

Permalink
chore: remove identity resolver from stardust (#968)
Browse files Browse the repository at this point in the history
* chore: remove identity resolver from stardust

* chore: revert changes

* fix: revert changes and rename resolver component

* fix: rename missing file

* fix: update imports

* chore: format

* chore: rename missing files

* fix: rename scss import

---------

Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
  • Loading branch information
VmMad and begonaalvarezd authored Jan 22, 2024
1 parent 3389eb2 commit f26ceb1
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 128 deletions.
3 changes: 2 additions & 1 deletion client/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const App: React.FC<RouteComponentProps<AppRouteProps>> = ({
}, [networksLoaded]);

const networkConfig = networks.find((n) => n.network === network);
const identityResolverEnabled = networkConfig?.identityResolverEnabled ?? true;
const protocolVersion = networkConfig?.protocolVersion ?? STARDUST;
const identityResolverEnabled = protocolVersion !== STARDUST && (networkConfig?.identityResolverEnabled ?? true);
const currentNetworkName = networkConfig?.network;
const isShimmer = isShimmerUiTheme(networkConfig?.uiTheme);
const nodeService = ServiceFactory.get<NodeInfoService>("node-info");
Expand Down
16 changes: 6 additions & 10 deletions client/src/app/AppUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export const getPages = (currentNetwork: INetwork | undefined, networks: INetwor
const pages = [];
if (networks.length > 0 && currentNetwork !== undefined) {
pages.push({ label: "Explorer", url: `/${currentNetwork.network}/` });
if (currentNetwork.network !== CHRYSALIS_MAINNET) {
pages.push({ label: "Visualizer", url: `/${currentNetwork.network}/visualizer/` });
}
pages.push({ label: "Visualizer", url: `/${currentNetwork.network}/visualizer/` });

if (currentNetwork.hasStatisticsSupport) {
pages.push({ label: "Statistics", url: `/${currentNetwork.network}/statistics/` });
Expand All @@ -42,7 +40,7 @@ export const getPages = (currentNetwork: INetwork | undefined, networks: INetwor

export const buildUtilities = (currentNetwork: string, networks: INetwork[], identityResolverEnabled: boolean) => {
const utilities = [];
if (networks.length > 0 && currentNetwork !== CHRYSALIS_MAINNET) {
if (networks.length > 0) {
utilities.push({ label: "Streams v0", url: `/${currentNetwork}/streams/0/` });
if (identityResolverEnabled) {
utilities.push({ label: "Decentralized Identifier", url: `/${currentNetwork}/identity-resolver/` });
Expand All @@ -63,13 +61,11 @@ export const getFooterItems = (currentNetwork: string, networks: INetwork[], ide
if (networks.length > 0) {
let footerArray = networks.filter((network) => network.isEnabled).map((n) => ({ label: n.label, url: n.network.toString() }));

if (currentNetwork !== CHRYSALIS_MAINNET) {
footerArray = footerArray
.concat({ label: "Streams v0", url: `${currentNetwork}/streams/0/` })
.concat({ label: "Visualizer", url: `${currentNetwork}/visualizer/` });
}
footerArray = footerArray
.concat({ label: "Streams v0", url: `${currentNetwork}/streams/0/` })
.concat({ label: "Visualizer", url: `${currentNetwork}/visualizer/` });

if (identityResolverEnabled && currentNetwork !== CHRYSALIS_MAINNET) {
if (identityResolverEnabled) {
footerArray.push({ label: "Identity Resolver", url: `${currentNetwork}/identity-resolver/` });
}

Expand Down
7 changes: 7 additions & 0 deletions client/src/app/components/JsonViewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
font-family: "Courier New", Courier, monospace;
white-space: pre-wrap;

@include font-size(12px, 20px);

color: var(--did-color);
font-family: $ibm-plex-mono;
letter-spacing: 0.02em;
white-space: pre-wrap;

.string {
color: green;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import {
LinkedDomainService,
} from "@iota/identity-wasm/web";
import React, { Fragment, useEffect, useState } from "react";
import IdentityDomainResolver from "./domains/IdentityDomainResolver";
import { IdentityStardustResolverProps } from "./IdentityStardustResolverProps";
import DIDDomainResolver from "./domains/DIDDomainResolver";
import { DIDResolverProps } from "./DIDResolverProps";
import { ServiceFactory } from "~factories/serviceFactory";
import { IdentityService } from "~services/identityService";
import "./IdentityStardustResolver.scss";
import "./DIDResolver.scss";
import CopyButton from "../CopyButton";
import JsonViewer from "../JsonViewer";
import Spinner from "../Spinner";
import { IIdentityStardustResolveResponse } from "~/models/api/IIdentityStardustResolveResponse";
import { IDIDResolverResponse } from "~/models/api/IDIDResolverResponse";

const IdentityStardustResolver: React.FC<IdentityStardustResolverProps> = ({ resolvedDID, network }) => {
const IdentityStardustResolver: React.FC<DIDResolverProps> = ({ resolvedDID, network }) => {
const [DID, setDID] = useState<string>("");
const [governorAddress, setGovernorAddress] = useState<string>("");
const [stateControllerAddress, setStateControllerAddress] = useState<string>("");
Expand Down Expand Up @@ -86,7 +86,7 @@ const IdentityStardustResolver: React.FC<IdentityStardustResolverProps> = ({ res

<div className="margin-b-s">
<div className="label">Linked Domains</div>
<IdentityDomainResolver verifiedDomains={verifiedDomains} />
<DIDDomainResolver verifiedDomains={verifiedDomains} />
</div>
</Fragment>
)}
Expand Down Expand Up @@ -146,7 +146,7 @@ const IdentityStardustResolver: React.FC<IdentityStardustResolverProps> = ({ res
// }
export default IdentityStardustResolver;

async function constructVerifiedDomains(resolvedDID: IIdentityStardustResolveResponse): Promise<Map<string, Promise<void>>> {
async function constructVerifiedDomains(resolvedDID: IDIDResolverResponse): Promise<Map<string, Promise<void>>> {
const newVerifiedDomains = new Map<string, Promise<void>>();

await ServiceFactory.get<IdentityService>("identity").initLibrary();
Expand Down
7 changes: 7 additions & 0 deletions client/src/app/components/identity/DIDResolverProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IDIDResolverResponse } from "~/models/api/IDIDResolverResponse";

export interface DIDResolverProps {
resolvedDID: IDIDResolverResponse | null;

network: string;
}
15 changes: 0 additions & 15 deletions client/src/app/components/identity/IdentitySearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,6 @@ class SearchInput extends AsyncComponent<IdentitySearchInputProps, IdentitySearc
private doSearch(): void {
this.props.onSearch(this.state.did);
}

private didContainsWrongNetwork(did: string, network: string): boolean {
const colonCountInDid = did.split(":").length - 1;

if (colonCountInDid !== 3) {
return false;
}

const networkNameInDid = did.split(":")[2];

if (networkNameInDid !== network) {
return true;
}
return false;
}
}

export default SearchInput;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { ReactNode } from "react";
import { IoAlertCircle, IoCheckmarkCircle } from "react-icons/io5";
import { IdentityDomainResolverProps } from "./IdentityDomainResolverProps";
import { IdentityDomainResolverState, Status } from "./IdentityDomainResolverState";
import { DIDDomainResolverProps } from "./DIDDomainResolverProps";
import { DIDDomainResolverState, Status } from "./DIDDomainResolverState";
import AsyncComponent from "../../AsyncComponent";
import "./IdentityDomainResolver.scss";
import "./DIDDomainResolver.scss";
import Spinner from "../../Spinner";
import Tooltip from "../../Tooltip";

class IdentityDomainResolver extends AsyncComponent<IdentityDomainResolverProps, IdentityDomainResolverState> {
constructor(props: IdentityDomainResolverProps) {
class DIDDomainResolver extends AsyncComponent<DIDDomainResolverProps, DIDDomainResolverState> {
constructor(props: DIDDomainResolverProps) {
super(props);
this.state = {
verifiedDomainsPresentation: new Map(),
Expand All @@ -20,7 +20,7 @@ class IdentityDomainResolver extends AsyncComponent<IdentityDomainResolverProps,
this.computeVerifiedDomainsPresentation(this.props.verifiedDomains);
}

public componentDidUpdate(prevProps: IdentityDomainResolverProps) {
public componentDidUpdate(prevProps: DIDDomainResolverProps) {
if (prevProps !== this.props) {
this.computeVerifiedDomainsPresentation(this.props.verifiedDomains);
}
Expand Down Expand Up @@ -59,8 +59,8 @@ class IdentityDomainResolver extends AsyncComponent<IdentityDomainResolverProps,
);
}

private computeVerifiedDomainsPresentation(verifiedDomains: IdentityDomainResolverProps["verifiedDomains"]) {
const newVerifiedDomainsPresentation: IdentityDomainResolverState["verifiedDomainsPresentation"] = new Map();
private computeVerifiedDomainsPresentation(verifiedDomains: DIDDomainResolverProps["verifiedDomains"]) {
const newVerifiedDomainsPresentation: DIDDomainResolverState["verifiedDomainsPresentation"] = new Map();
if (verifiedDomains) {
for (const [key, value] of verifiedDomains.entries()) {
newVerifiedDomainsPresentation.set(key, { status: Status.InFlight });
Expand All @@ -87,4 +87,4 @@ class IdentityDomainResolver extends AsyncComponent<IdentityDomainResolverProps,
});
}
}
export default IdentityDomainResolver;
export default DIDDomainResolver;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface IdentityDomainResolverProps {
export interface DIDDomainResolverProps {
verifiedDomains?: Map<string, Promise<void>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export enum Status {
Error = "ERROR",
}

export interface IdentityDomainResolverState {
export interface DIDDomainResolverState {
verifiedDomainsPresentation: Map<
string,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import IdentityStardustResolver from "../../../../identity/IdentityStardustResolver";
import { IIdentityStardustResolveResponse } from "~/models/api/IIdentityStardustResolveResponse";
import IdentityStardustResolver from "../../../../identity/DIDResolver";
import { IDIDResolverResponse } from "~/models/api/IDIDResolverResponse";

interface DIDSectionProps {
resolvedDID: IIdentityStardustResolveResponse | null;
resolvedDID: IDIDResolverResponse | null;
network: string;
}

Expand Down
11 changes: 9 additions & 2 deletions client/src/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ const buildAppRoutes = (protocolVersion: string, withNetworkContext: (wrappedCom
key={keys.next().value}
component={(props: RouteComponentProps<StreamsV0RouteProps>) => <StreamsV0 {...props} />}
/>,
];

const IdentiyResolverRoute = (
<Route
path="/:network/identity-resolver/:did?"
key={keys.next().value}
component={(props: RouteComponentProps<IdentityResolverProps>) => (
<IdentityResolver {...props} protocolVersion={protocolVersion} />
)}
/>,
];
/>
);

if (protocolVersion !== STARDUST) {
commonRoutes.push(IdentiyResolverRoute);
}

const legacyRoutes = [
<Route
Expand Down
65 changes: 10 additions & 55 deletions client/src/app/routes/IdentityResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { RouteComponentProps } from "react-router-dom";
import welcomeMessage from "~assets/modals/identity-resolver/welcome.json";
import { IdentityResolverProps } from "./IdentityResolverProps";
import { IdentityResolverState } from "./IdentityResolverState";
import { ServiceFactory } from "~factories/serviceFactory";
import { CHRYSALIS, LEGACY, STARDUST } from "~models/config/protocolVersion";
import { NetworkService } from "~services/networkService";
import { CHRYSALIS } from "~models/config/protocolVersion";
import AsyncComponent from "../components/AsyncComponent";
import IdentityChrysalisResolver from "../components/identity/IdentityChrysalisResolver";
import IdentitySearchInput from "../components/identity/IdentitySearchInput";
Expand All @@ -19,16 +17,10 @@ class IdentityResolver extends AsyncComponent<
> {
constructor(props: RouteComponentProps<IdentityResolverProps> & { protocolVersion: string }) {
super(props);

this.state = {
didExample: undefined,
};
}

public async componentDidMount(): Promise<void> {
super.componentDidMount();

this.setDidExample();
}

/**
Expand All @@ -44,10 +36,6 @@ class IdentityResolver extends AsyncComponent<
<div className="cards">
{!this.props.match.params.did && (
<Fragment>
{this.props.protocolVersion === LEGACY && (
<div className="unsupported-network">This network is not supported!</div>
)}

<div>
<div className="row middle">
<h1>Decentralized Identifier</h1>
Expand All @@ -61,45 +49,22 @@ class IdentityResolver extends AsyncComponent<
network.
</p>
</div>
{this.props.protocolVersion !== LEGACY && (
<div className="row middle margin-b-s row--tablet-responsive">
<IdentitySearchInput
compact={false}
onSearch={(e) => {
this.props.history.push(
`/${this.props.match.params.network}/identity-resolver/${e}`,
);
}}
network={this.props.match.params.network}
/>
</div>
)}

{this.state.didExample && this.props.protocolVersion === STARDUST && (
<button
className="load-history-button"
onClick={() => {
<div className="row middle margin-b-s row--tablet-responsive">
<IdentitySearchInput
compact={false}
onSearch={(e) => {
this.props.history.push(
`/${this.props.match.params.network}/identity-resolver/${this.state.didExample}`,
`/${this.props.match.params.network}/identity-resolver/${e}`,
);
}}
type="button"
>
DID Example
</button>
)}
network={this.props.match.params.network}
/>
</div>
</div>
</Fragment>
)}
{this.props.match.params.did && (
<div>
{this.props.protocolVersion === LEGACY && (
<div>
<div className="unsupported-network">This network is not supported!</div>
</div>
)}
{this.props.protocolVersion === CHRYSALIS && <IdentityChrysalisResolver {...this.props} />}
</div>
<div>{this.props.protocolVersion === CHRYSALIS && <IdentityChrysalisResolver {...this.props} />}</div>
)}
</div>
</div>
Expand All @@ -108,16 +73,6 @@ class IdentityResolver extends AsyncComponent<
</div>
);
}

private setDidExample() {
const networkService = ServiceFactory.get<NetworkService>("network");
const networks = networkService.networks();

const network = networks.find((n) => n.network === this.props.match.params.network);
this.setState({
didExample: network?.didExample,
});
}
}

export default IdentityResolver;
4 changes: 2 additions & 2 deletions client/src/app/routes/stardust/AddressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import NetworkContext from "../../context/NetworkContext";
import { AddressRouteProps } from "../AddressRouteProps";
import { useAliasContainsDID } from "~/helpers/hooks/useAliasContainsDID";
import { useResolvedDID } from "~/helpers/hooks/useResolvedDID";
import { IIdentityStardustResolveResponse } from "~/models/api/IIdentityStardustResolveResponse";
import { IDIDResolverResponse } from "~/models/api/IDIDResolverResponse";

export interface IAddressState {
bech32AddressDetails: IBech32AddressDetails | null;
Expand Down Expand Up @@ -63,7 +63,7 @@ export interface IAddressState {
associatedOutputCount: number;
aliasContainsDID: boolean;
isDIDLoading: boolean;
resolvedDID: IIdentityStardustResolveResponse | null;
resolvedDID: IDIDResolverResponse | null;
}

const initialState = {
Expand Down
10 changes: 3 additions & 7 deletions client/src/helpers/hooks/useResolvedDID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { useIsMounted } from "./useIsMounted";
import { ServiceFactory } from "~factories/serviceFactory";
import { IdentityService } from "~/services/identityService";
import { IIdentityStardustResolveResponse } from "~/models/api/IIdentityStardustResolveResponse";
import { IDIDResolverResponse } from "~/models/api/IDIDResolverResponse";

/**
* Fetch resolved DID
Expand All @@ -11,14 +11,10 @@ import { IIdentityStardustResolveResponse } from "~/models/api/IIdentityStardust
* @param addressHex Hex representation of the alias address
* @returns The DID response and loading bool.
*/
export function useResolvedDID(
network: string,
bech32Hrp: string,
addressHex: string | null,
): [IIdentityStardustResolveResponse | null, boolean] {
export function useResolvedDID(network: string, bech32Hrp: string, addressHex: string | null): [IDIDResolverResponse | null, boolean] {
const isMounted = useIsMounted();
const [identityService] = useState(ServiceFactory.get<IdentityService>("identity"));
const [identityResponse, setidentityResponse] = useState<IIdentityStardustResolveResponse | null>(null);
const [identityResponse, setidentityResponse] = useState<IDIDResolverResponse | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IIdentityStardustResolveRequest {
export interface IDIDResolverRequest {
/**
* The network to search on.
*/
Expand Down
Loading

0 comments on commit f26ceb1

Please sign in to comment.