Skip to content

Commit

Permalink
Added did:key method (#755)
Browse files Browse the repository at this point in the history
Signed-off-by: Himalayan Dev <[email protected]>
  • Loading branch information
himalayan-dev authored Oct 21, 2024
1 parent 70fccd3 commit 0529234
Show file tree
Hide file tree
Showing 80 changed files with 1,592 additions and 1,858 deletions.
22 changes: 0 additions & 22 deletions packages/hedera-identify-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,8 @@
"start": "yarn workspaces foreach --parallel --interlaced --verbose run start",
"test": "yarn workspaces foreach --parallel --interlaced --verbose run test"
},
"devDependencies": {
"@metamask/eslint-config": "^11.1.0",
"@metamask/eslint-config-jest": "^11.1.0",
"@metamask/eslint-config-nodejs": "^11.1.0",
"@metamask/eslint-config-typescript": "^11.1.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.38.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.4.0",
"eslint-plugin-jsdoc": "^46.8.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^3.0.3",
"prettier-plugin-packagejson": "^2.4.5",
"typescript": "^5.2.2"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=18.13.0"
},
"dependencies": {
"@yarnpkg/plugin-workspace-tools": "^4.1.0",
"protobufjs": "^7.4.0"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from '../../contexts/MetamaskContext';
import useModal from '../../hooks/useModal';
import {
PublicAccountInfo,
getAccountInfo,
getCurrentMetamaskAccount,
getCurrentNetwork,
Expand All @@ -35,6 +34,7 @@ import { Card, SendHelloButton } from '../base';
import ExternalAccount, {
GetExternalAccountRef,
} from '../sections/ExternalAccount';
import { PublicAccountInfo } from '../../types/snap';

type Props = {
setMetamaskAddress: React.Dispatch<React.SetStateAction<string>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*-
*
* Hedera Identify Snap
*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { FC, useContext, useState } from 'react';
import Form from 'react-bootstrap/esm/Form';
import {
MetaMaskContext,
MetamaskActions,
} from '../../contexts/MetamaskContext';
import {
getCurrentMetamaskAccount,
getCurrentNetwork,
shouldDisplayReconnectButton,
switchDIDMethod,
} from '../../utils';
import { Card, SendHelloButton } from '../base';

type Props = {
setMetamaskAddress: React.Dispatch<React.SetStateAction<string>>;
setCurrentChainId: React.Dispatch<React.SetStateAction<string>>;
};

const SwitchDIDMethod: FC<Props> = ({
setMetamaskAddress,
setCurrentChainId,
}) => {
const [state, dispatch] = useContext(MetaMaskContext);
const [didMethod, setDidMethod] = useState('did:pkh'); // Default method is 'did:pkh'
const [loading, setLoading] = useState(false);

const handleswitchDIDMethodClick = async () => {
setLoading(true);
try {
const metamaskAddress = await getCurrentMetamaskAccount();
setMetamaskAddress(metamaskAddress);
setCurrentChainId(await getCurrentNetwork());

const switched = await switchDIDMethod(metamaskAddress, didMethod);
console.log(`DID Method switched : ${switched}`);
} catch (e) {
console.error(e);
dispatch({ type: MetamaskActions.SetError, payload: e });
}
setLoading(false);
};

return (
<Card
content={{
title: 'switchDIDMethod',
description: 'Select and switch DID Method to use',
form: (
<>
<Form.Check
type="radio"
label="did:pkh (default)"
name="didMethod"
value="did:pkh"
checked={didMethod === 'did:pkh'}
onChange={(e) => setDidMethod(e.target.value)}
style={{ marginBottom: 8 }}
/>
<Form.Check
type="radio"
label="did:key"
name="didMethod"
value="did:key"
checked={didMethod === 'did:key'}
onChange={(e) => setDidMethod(e.target.value)}
style={{ marginBottom: 8 }}
/>
<Form.Check
type="radio"
label="did:hedera"
name="didMethod"
value="did:hedera"
checked={didMethod === 'did:hedera'}
onChange={(e) => setDidMethod(e.target.value)}
style={{ marginBottom: 8 }}
/>
</>
),
button: (
<SendHelloButton
buttonText="Switch DID Method"
onClick={handleswitchDIDMethodClick}
disabled={!state.installedSnap}
loading={loading}
/>
),
}}
disabled={!state.installedSnap}
fullWidth={
state.isFlask &&
Boolean(state.installedSnap) &&
!shouldDisplayReconnectButton(state.installedSnap)
}
/>
);
};

export { SwitchDIDMethod };
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

export { ConfigureGoogleAccount } from './ConfigureGoogleAccount';
export { ConnectIdentitySnap } from './ConnectIdentitySnap';
export { CreateNewHederaAccount } from './CreateNewHederaAccount';
export { CreateVC } from './CreateVC';
export { DeleteAllVCs } from './DeleteAllVCs';
export { GetAccountInfo } from './GetAccountInfo';
Expand Down
Loading

0 comments on commit 0529234

Please sign in to comment.