-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Himalayan Dev <[email protected]> Signed-off-by: Himalayan Dev <[email protected]>
- Loading branch information
1 parent
8590a47
commit 3e72195
Showing
19 changed files
with
15,398 additions
and
6,268 deletions.
There are no files selected for viewing
File renamed without changes.
143 changes: 143 additions & 0 deletions
143
packages/hedera-wallet-snap/packages/site/src/components/cards/hts/DisableKYCAccount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/*- | ||
* | ||
* Hedera Wallet 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, useRef, useState } from 'react'; | ||
import { | ||
MetaMaskContext, | ||
MetamaskActions, | ||
} from '../../../contexts/MetamaskContext'; | ||
import useModal from '../../../hooks/useModal'; | ||
import { | ||
Account, | ||
FreezeOrEnableKYCAccountRequestParams, | ||
} from '../../../types/snap'; | ||
import { | ||
disableKYCAccount, | ||
shouldDisplayReconnectButton, | ||
} from '../../../utils'; | ||
import { Card, SendHelloButton } from '../../base'; | ||
import { GetExternalAccountRef } from '../../sections/ExternalAccount'; | ||
|
||
type Props = { | ||
network: string; | ||
mirrorNodeUrl: string; | ||
setAccountInfo: React.Dispatch<React.SetStateAction<Account>>; | ||
}; | ||
|
||
const DisableKYCAccount: FC<Props> = ({ | ||
network, | ||
mirrorNodeUrl, | ||
setAccountInfo, | ||
}) => { | ||
const [state, dispatch] = useContext(MetaMaskContext); | ||
const [loading, setLoading] = useState(false); | ||
const { showModal } = useModal(); | ||
const [tokenId, setTokenId] = useState(''); | ||
const [accountId, setAccountId] = useState(''); | ||
|
||
const externalAccountRef = useRef<GetExternalAccountRef>(null); | ||
|
||
const handleDisableKYCAccountClick = async () => { | ||
setLoading(true); | ||
try { | ||
const externalAccountParams = | ||
externalAccountRef.current?.handleGetAccountParams(); | ||
|
||
const disableKYCAccountParams = { | ||
tokenId, | ||
accountId, | ||
} as FreezeOrEnableKYCAccountRequestParams; | ||
|
||
const response: any = await disableKYCAccount( | ||
network, | ||
mirrorNodeUrl, | ||
disableKYCAccountParams, | ||
externalAccountParams, | ||
); | ||
|
||
const { receipt, currentAccount } = response; | ||
|
||
setAccountInfo(currentAccount); | ||
console.log('receipt: ', receipt); | ||
|
||
showModal({ | ||
title: 'Transaction Receipt', | ||
content: JSON.stringify({ receipt }, null, 4), | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
dispatch({ type: MetamaskActions.SetError, payload: e }); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<Card | ||
content={{ | ||
title: 'disableKYCAccount', | ||
description: | ||
'Revokes the KYC flag to the Hedera account for the given Hedera token.', | ||
form: ( | ||
<> | ||
<label> | ||
Enter the token Id to use | ||
<input | ||
type="string" | ||
style={{ width: '100%' }} | ||
value={tokenId} | ||
placeholder="Enter Token Id(0.0.x)" | ||
onChange={(e) => setTokenId(e.target.value)} | ||
/> | ||
</label> | ||
<br /> | ||
|
||
<label> | ||
Enter the account Id to revoke KYC from | ||
<input | ||
type="string" | ||
style={{ width: '100%' }} | ||
value={accountId} | ||
placeholder="Enter Account Id(0.0.x)" | ||
onChange={(e) => setAccountId(e.target.value)} | ||
/> | ||
</label> | ||
<br /> | ||
</> | ||
), | ||
button: ( | ||
<SendHelloButton | ||
buttonText="Revoke KYC" | ||
onClick={handleDisableKYCAccountClick} | ||
disabled={!state.installedSnap} | ||
loading={loading} | ||
/> | ||
), | ||
}} | ||
disabled={!state.installedSnap} | ||
fullWidth={ | ||
state.isFlask && | ||
Boolean(state.installedSnap) && | ||
!shouldDisplayReconnectButton(state.installedSnap) | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export { DisableKYCAccount }; |
140 changes: 140 additions & 0 deletions
140
packages/hedera-wallet-snap/packages/site/src/components/cards/hts/EnableKYCAccount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/*- | ||
* | ||
* Hedera Wallet 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, useRef, useState } from 'react'; | ||
import { | ||
MetaMaskContext, | ||
MetamaskActions, | ||
} from '../../../contexts/MetamaskContext'; | ||
import useModal from '../../../hooks/useModal'; | ||
import { | ||
Account, | ||
FreezeOrEnableKYCAccountRequestParams, | ||
} from '../../../types/snap'; | ||
import { enableKYCAccount, shouldDisplayReconnectButton } from '../../../utils'; | ||
import { Card, SendHelloButton } from '../../base'; | ||
import { GetExternalAccountRef } from '../../sections/ExternalAccount'; | ||
|
||
type Props = { | ||
network: string; | ||
mirrorNodeUrl: string; | ||
setAccountInfo: React.Dispatch<React.SetStateAction<Account>>; | ||
}; | ||
|
||
const EnableKYCAccount: FC<Props> = ({ | ||
network, | ||
mirrorNodeUrl, | ||
setAccountInfo, | ||
}) => { | ||
const [state, dispatch] = useContext(MetaMaskContext); | ||
const [loading, setLoading] = useState(false); | ||
const { showModal } = useModal(); | ||
const [tokenId, setTokenId] = useState(''); | ||
const [accountId, setAccountId] = useState(''); | ||
|
||
const externalAccountRef = useRef<GetExternalAccountRef>(null); | ||
|
||
const handleEnableKYCAccountClick = async () => { | ||
setLoading(true); | ||
try { | ||
const externalAccountParams = | ||
externalAccountRef.current?.handleGetAccountParams(); | ||
|
||
const enableKYCAccountParams = { | ||
tokenId, | ||
accountId, | ||
} as FreezeOrEnableKYCAccountRequestParams; | ||
|
||
const response: any = await enableKYCAccount( | ||
network, | ||
mirrorNodeUrl, | ||
enableKYCAccountParams, | ||
externalAccountParams, | ||
); | ||
|
||
const { receipt, currentAccount } = response; | ||
|
||
setAccountInfo(currentAccount); | ||
console.log('receipt: ', receipt); | ||
|
||
showModal({ | ||
title: 'Transaction Receipt', | ||
content: JSON.stringify({ receipt }, null, 4), | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
dispatch({ type: MetamaskActions.SetError, payload: e }); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<Card | ||
content={{ | ||
title: 'enableKYCAccount', | ||
description: | ||
'Grants KYC to the Hedera accounts for the given Hedera token.', | ||
form: ( | ||
<> | ||
<label> | ||
Enter the token Id to use | ||
<input | ||
type="string" | ||
style={{ width: '100%' }} | ||
value={tokenId} | ||
placeholder="Enter Token Id(0.0.x)" | ||
onChange={(e) => setTokenId(e.target.value)} | ||
/> | ||
</label> | ||
<br /> | ||
|
||
<label> | ||
Enter the account Id to grant KYC to | ||
<input | ||
type="string" | ||
style={{ width: '100%' }} | ||
value={accountId} | ||
placeholder="Enter Account Id(0.0.x)" | ||
onChange={(e) => setAccountId(e.target.value)} | ||
/> | ||
</label> | ||
<br /> | ||
</> | ||
), | ||
button: ( | ||
<SendHelloButton | ||
buttonText="Grant KYC" | ||
onClick={handleEnableKYCAccountClick} | ||
disabled={!state.installedSnap} | ||
loading={loading} | ||
/> | ||
), | ||
}} | ||
disabled={!state.installedSnap} | ||
fullWidth={ | ||
state.isFlask && | ||
Boolean(state.installedSnap) && | ||
!shouldDisplayReconnectButton(state.installedSnap) | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export { EnableKYCAccount }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.