|
| 1 | +import React, {useState} from 'react' |
| 2 | +import GovToolsPanel from '../govToolsPanel' |
| 3 | +import CheckboxWithLabel from '../../checkboxWithLabel' |
| 4 | +import InputWithLabel from '../../inputWithLabel' |
| 5 | +import {protocolParams} from '../../../utils/networkConfig' |
| 6 | +import {getCertOfNewStakeDereg, getStakeKeyDeregCert, getStakeKeyDeregCertWithCoin} from '../../../utils/cslTools' |
| 7 | + |
| 8 | +const UnregisterStakeKeyPanel = (props) => { |
| 9 | + const {wasm, onWaiting, onError, getters, setters, handleInputCreds} = props |
| 10 | + const {getCertBuilder} = getters |
| 11 | + const {handleAddingCertInTx} = setters |
| 12 | + |
| 13 | + const [stakeKeyHash, setStakeKeyHash] = useState('') |
| 14 | + const [stakeDepositRefundAmount, setStakeDepositRefundAmount] = useState(protocolParams.keyDeposit) |
| 15 | + const [useConway, setUseConway] = useState(false) |
| 16 | + |
| 17 | + const handleUseConwayCert = () => { |
| 18 | + setUseConway(!useConway) |
| 19 | + console.debug(`[dApp][UnregisterStakeKeyPanel] use Conway Stake Registration Certificate is set: ${!useConway}`) |
| 20 | + } |
| 21 | + |
| 22 | + const buildUnregStakeKey = () => { |
| 23 | + onWaiting(true) |
| 24 | + const certBuilder = getCertBuilder(wasm) |
| 25 | + try { |
| 26 | + const stakeCred = handleInputCreds(stakeKeyHash) |
| 27 | + let stakeKeyDeregCert |
| 28 | + if (useConway) { |
| 29 | + stakeKeyDeregCert = getStakeKeyDeregCertWithCoin(wasm, stakeCred, stakeDepositRefundAmount) |
| 30 | + } else { |
| 31 | + stakeKeyDeregCert = getStakeKeyDeregCert(wasm, stakeCred) |
| 32 | + } |
| 33 | + certBuilder.add(getCertOfNewStakeDereg(wasm, stakeKeyDeregCert)) |
| 34 | + handleAddingCertInTx(certBuilder) |
| 35 | + onWaiting(false) |
| 36 | + } catch (error) { |
| 37 | + console.error(error) |
| 38 | + onWaiting(false) |
| 39 | + onError() |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + const panelProps = { |
| 44 | + buttonName: 'Build Cert', |
| 45 | + certLabel: 'unregStakeKey', |
| 46 | + clickFunction: buildUnregStakeKey, |
| 47 | + } |
| 48 | + |
| 49 | + return ( |
| 50 | + <GovToolsPanel {...panelProps}> |
| 51 | + <CheckboxWithLabel |
| 52 | + currentState={useConway} |
| 53 | + onChangeFunc={handleUseConwayCert} |
| 54 | + name="useNewConwayStakeRegCert" |
| 55 | + labelText="Use the new Conway Stake Unregistration Certificate (with coin)" |
| 56 | + /> |
| 57 | + <InputWithLabel |
| 58 | + inputName="Stake Key Hash" |
| 59 | + inputValue={stakeKeyHash} |
| 60 | + onChangeFunction={(event) => { |
| 61 | + setStakeKeyHash(event.target.value) |
| 62 | + }} |
| 63 | + /> |
| 64 | + <InputWithLabel |
| 65 | + inputName="Stake Key Deposit Refund Amount (lovelaces)" |
| 66 | + helpText="This should be align with how was paid during the registration" |
| 67 | + inputValue={stakeDepositRefundAmount} |
| 68 | + onChangeFunction={(event) => { |
| 69 | + setStakeDepositRefundAmount(event.target.value) |
| 70 | + }} |
| 71 | + /> |
| 72 | + </GovToolsPanel> |
| 73 | + ) |
| 74 | +} |
| 75 | + |
| 76 | +export default UnregisterStakeKeyPanel |
0 commit comments