diff --git a/src/components/tabs/subtabs/govBasicFunctionsTab.js b/src/components/tabs/subtabs/govBasicFunctionsTab.js
index e483045..3f1f150 100644
--- a/src/components/tabs/subtabs/govBasicFunctionsTab.js
+++ b/src/components/tabs/subtabs/govBasicFunctionsTab.js
@@ -1,42 +1,65 @@
import React from 'react'
import TabsComponent from '../tabsComponent'
-import VoteDelegationPanel from '../../cards/voteDelegationPanel'
+import VoteDelegationPanel from '../../cards/govActions/voteDelegationPanel'
+import {getCslCredentialFromBech32, getCslCredentialFromHex} from '../../../utils/cslTools'
+import DRepRegistrationPanel from '../../cards/govActions/dRepRegistrationPanel'
+import DRepUpdatePanel from '../../cards/govActions/dRepUpdatePanel'
+import DRepRetirementPanel from '../../cards/govActions/dRepRetirementPanel'
+import VotePanel from '../../cards/govActions/votePanel'
const GovBasicFunctionsTab = ({api, wasm, onWaiting, onError, getters, setters}) => {
+ const handleInputCreds = (input) => {
+ try {
+ return getCslCredentialFromHex(wasm, input)
+ } catch (err1) {
+ try {
+ return getCslCredentialFromBech32(wasm, input)
+ } catch (err2) {
+ onWaiting(false)
+ console.error(
+ `Error in parsing credential, not Hex or Bech32: ${JSON.stringify(err1)}, ${JSON.stringify(err2)}`,
+ )
+ onError()
+ return null
+ }
+ }
+ }
+
+ const panelsProps = {
+ api,
+ wasm,
+ onWaiting,
+ onError,
+ getters,
+ setters,
+ handleInputCreds,
+ }
+
const data = [
{
label: 'Vote Delegation',
value: 'voteDeleg',
- children: (
-
- ),
+ children:
,
},
{
label: 'DRep Registration',
value: 'drepReg',
- children: <>>,
+ children:
,
},
{
label: 'DRep Update',
value: 'drepUpdate',
- children: <>>,
+ children:
,
},
{
label: 'DRep Retirement',
value: 'drepRet',
- children: <>>,
+ children:
,
},
{
label: 'Vote',
value: 'vote',
- children: <>>,
+ children:
,
},
{
label: 'Register Stake Key',
diff --git a/src/components/tabs/subtabs/infoPanel.js b/src/components/tabs/subtabs/infoPanel.js
index 1d1b471..f32d79d 100644
--- a/src/components/tabs/subtabs/infoPanel.js
+++ b/src/components/tabs/subtabs/infoPanel.js
@@ -3,14 +3,16 @@ import React from 'react'
// We need getters here
const InfoPanel = ({getters}) => {
const {
- currentBalance,
- currentUtxos,
- currentChangeAddress,
- currentRewardAddress,
- currentDRepIdBech32,
- currentDRepIdHex,
- currentRegPubStakeKey,
- currentUnregPubStakeKey,
+ balance,
+ utxos,
+ changeAddress,
+ rewardAddress,
+ usedAddress,
+ unusedAddress,
+ dRepIdBech32,
+ dRepIdHex,
+ regPubStakeKey,
+ unregPubStakeKey,
} = getters
const textColor = 'text-orange-700'
@@ -20,12 +22,12 @@ const InfoPanel = ({getters}) => {
Balance:
- {currentBalance.length > 0 ? currentBalance : '-'}
+ {balance.length > 0 ? balance : '-'}
UTxOs:
- {currentUtxos.length > 0 ? (
- currentUtxos.map((utxo, index) => (
+ {utxos.length > 0 ? (
+ utxos.map((utxo, index) => (
{utxo}
@@ -37,28 +39,36 @@ const InfoPanel = ({getters}) => {
Change address:
- {currentChangeAddress.length > 0 ? currentChangeAddress : '-'}
+ {changeAddress.length > 0 ? changeAddress : '-'}
Reward address:
- {currentRewardAddress.length > 0 ? currentRewardAddress : '-'}
+ {rewardAddress.length > 0 ? rewardAddress : '-'}
+
+
+ Used address:
+ {usedAddress.length > 0 ? usedAddress : '-'}
+
+
+ Unused address:
+ {unusedAddress.length > 0 ? unusedAddress : '-'}
DRep ID Hex:
- {currentDRepIdHex.length > 0 ? currentDRepIdHex : '-'}
+ {dRepIdHex.length > 0 ? dRepIdHex : '-'}
DRep ID Bech32:
- {currentDRepIdBech32.length > 0 ? currentDRepIdBech32 : '-'}
+ {dRepIdBech32.length > 0 ? dRepIdBech32 : '-'}
Registered public key (first):
- {currentRegPubStakeKey.length > 0 ? currentRegPubStakeKey : '-'}
+ {regPubStakeKey.length > 0 ? regPubStakeKey : '-'}
Unregistered public key (first):
- {currentUnregPubStakeKey.length > 0 ? currentUnregPubStakeKey : '-'}
+ {unregPubStakeKey.length > 0 ? unregPubStakeKey : '-'}
diff --git a/src/utils/cslTools.js b/src/utils/cslTools.js
index 9e1eca8..cd1e4c2 100644
--- a/src/utils/cslTools.js
+++ b/src/utils/cslTools.js
@@ -1,23 +1,31 @@
+import {protocolParams} from './networkConfig'
import {hexToBytes, bytesToHex, wasmMultiassetToJSONs} from './utils'
import {Buffer} from 'buffer'
export const toInt = (wasm, number) => wasm.Int.new_i32(number)
+export const strToBigNum = (wasm, numberIsStr) => wasm.BigNum.from_str(numberIsStr)
+
export const getTxBuilder = (wasm) => {
return wasm.TransactionBuilder.new(
wasm.TransactionBuilderConfigBuilder.new()
- .fee_algo(wasm.LinearFee.new(wasm.BigNum.from_str('44'), wasm.BigNum.from_str('155381')))
- .coins_per_utxo_word(wasm.BigNum.from_str('34482'))
- .pool_deposit(wasm.BigNum.from_str('500000000'))
- .key_deposit(wasm.BigNum.from_str('2000000'))
+ .fee_algo(
+ wasm.LinearFee.new(
+ strToBigNum(wasm, protocolParams.linearFee.minFeeA),
+ strToBigNum(wasm, protocolParams.linearFee.minFeeB),
+ ),
+ )
+ .pool_deposit(strToBigNum(wasm, protocolParams.poolDeposit))
+ .key_deposit(strToBigNum(wasm, protocolParams.keyDeposit))
+ .coins_per_utxo_word(strToBigNum(wasm, protocolParams.coinsPerUtxoWord))
+ .max_value_size(protocolParams.maxValueSize)
+ .max_tx_size(protocolParams.maxTxSize)
.ex_unit_prices(
wasm.ExUnitPrices.new(
- wasm.UnitInterval.new(wasm.BigNum.from_str('577'), wasm.BigNum.from_str('10000')),
- wasm.UnitInterval.new(wasm.BigNum.from_str('721'), wasm.BigNum.from_str('10000000')),
+ wasm.UnitInterval.new(strToBigNum(wasm, '577'), strToBigNum(wasm, '10000')),
+ wasm.UnitInterval.new(strToBigNum(wasm, '721'), strToBigNum(wasm, '10000000')),
),
)
- .max_value_size(5000)
- .max_tx_size(16384)
.build(),
)
}
@@ -34,13 +42,22 @@ export const getCslUtxos = (wasm, hexUtxos) => {
export const getLargestFirstMultiAsset = (wasm) => wasm.CoinSelectionStrategyCIP2.LargestFirstMultiAsset
-export const getTransactionOutput = (wasm, wasmOutputAddress, buildTransactionInput) =>
- wasm.TransactionOutput.new(wasmOutputAddress, wasm.Value.new(wasm.BigNum.from_str(buildTransactionInput.amount)))
+export const getTransactionOutput = (wasm, wasmOutputAddress, buildTransactionInput) => {
+ if (buildTransactionInput.amount) {
+ return wasm.TransactionOutput.new(
+ wasmOutputAddress,
+ wasm.Value.new(strToBigNum(wasm, buildTransactionInput.amount)),
+ )
+ }
+ return wasm.TransactionOutput.new(wasmOutputAddress, wasm.Value.new(buildTransactionInput))
+}
export const getAddressFromBytes = (wasm, changeAddress) => wasm.Address.from_bytes(hexToBytes(changeAddress))
export const getTransactionFromBytes = (wasm, txHex) => wasm.Transaction.from_bytes(hexToBytes(txHex))
+export const getTransactionWitnessSetNew = (wasm) => wasm.TransactionWitnessSet.new()
+
export const getTransactionWitnessSetFromBytes = (wasm, witnessHex) =>
wasm.TransactionWitnessSet.from_bytes(hexToBytes(witnessHex))
@@ -60,6 +77,8 @@ export const getAssetName = (wasm, assetNameString) => wasm.AssetName.new(Buffer
export const getBech32AddressFromHex = (wasm, addressHex) => wasm.Address.from_bytes(hexToBytes(addressHex)).to_bech32()
+export const getAddressFromBech32 = (wasm, bech32Value) => wasm.Address.from_bech32(bech32Value)
+
export const getCslValue = (wasm, hexValue) => wasm.Value.from_bytes(hexToBytes(hexValue))
export const getUtxoFromHex = (wasm, hexUtxo) => {
@@ -72,23 +91,16 @@ export const getUtxoFromHex = (wasm, hexUtxo) => {
utxo.receiver = output.address().to_bech32()
utxo.amount = output.amount().coin().to_str()
utxo.asset = wasmMultiassetToJSONs(output.amount().multiasset())
+ utxo.hex = hexUtxo
return utxo
}
+export const getTransactionHashFromHex = (wasm, txHex) => wasm.TransactionHash.from_hex(txHex)
+
export const getCertificateBuilder = (wasm) => wasm.CertificatesBuilder.new()
export const getCredential = (wasm, keyHash) => wasm.Credential.from_keyhash(keyHash)
-export const getVotingBuilder = (wasm) => wasm.VotingBuilder.new()
-
-export const getVoterFromDRepIDHex = (wasm, dRepIDHex) => {
- if (dRepIDHex) {
- const dRepKeyHash = keyHashFromHex(dRepIDHex)
- return wasm.Voter.new_drep(getCredential(wasm, dRepKeyHash))
- }
- throw new Error('DRepIDHex is empty, you need to get it first')
-}
-
export const keyHashFromHex = (wasm, hexValue) => wasm.Ed25519KeyHash.from_hex(hexValue)
export const keyHashFromBech32 = (wasm, bech32Value) => wasm.Ed25519KeyHash.from_bech32(bech32Value)
@@ -117,6 +129,53 @@ export const getDRepNoConfidence = (wasm) => wasm.DRep.new_always_no_confidence(
export const getDRepNewKeyHash = (wasm, credHash) => wasm.DRep.new_key_hash(credHash)
+export const getURL = (wasm, url) => wasm.URL.new(url)
+
+export const getAnchorHash = (wasm, urlHash) => wasm.AnchorDataHash.from_hex(urlHash)
+
+export const getAnchor = (wasm, url, urlHash) => {
+ const anchorURL = getURL(wasm, url)
+ const anchorHash = getAnchorHash(wasm, urlHash)
+ return wasm.Anchor.new(anchorURL, anchorHash)
+}
+
+// Vote Delegation Certificate
export const getVoteDelegCert = (wasm, stakeCred, dRepKeyHash) => wasm.VoteDelegation.new(stakeCred, dRepKeyHash)
export const getCertOfNewVoteDelegation = (wasm, voteCert) => wasm.Certificate.new_vote_delegation(voteCert)
+
+// DRep Registration Certificate
+export const getDRepRegCert = (wasm, dRepCred, dRepDeposit) =>
+ wasm.DrepRegistration.new(dRepCred, strToBigNum(wasm, dRepDeposit))
+
+export const getDRepRegWithAnchorCert = (wasm, dRepCred, dRepDeposit, anchor) =>
+ wasm.DrepRegistration.new_with_anchor(dRepCred, strToBigNum(wasm, dRepDeposit), anchor)
+
+export const getCertOfNewDRepReg = (wasm, dRepRegCert) => wasm.Certificate.new_drep_registration(dRepRegCert)
+
+// DRep Update Certificate
+export const getDRepUpdateCert = (wasm, dRepCred) => wasm.DrepUpdate.new(dRepCred)
+
+export const getDRepUpdateWithAnchorCert = (wasm, dRepCred, anchor) => wasm.DrepUpdate.new_with_anchor(dRepCred, anchor)
+
+export const getCertOfNewDRepUpdate = (wasm, dRepUpdateCert) => wasm.Certificate.new_drep_update(dRepUpdateCert)
+
+// DRep Retirement Certificate
+export const getDRepRetirementCert = (wasm, dRepCred, dRepRefundAmount) =>
+ wasm.DrepDeregistration.new(dRepCred, strToBigNum(wasm, dRepRefundAmount))
+
+export const getCertOfNewDRepRetirement = (wasm, dRepRetirementCert) =>
+ wasm.Certificate.new_drep_deregistration(dRepRetirementCert)
+
+// Vote
+export const getVotingProcedureWithAnchor = (wasm, votingChoice, anchor) =>
+ wasm.VotingProcedure.new_with_anchor(votingChoice, anchor)
+
+export const getCslVotingBuilder = (wasm) => wasm.VotingBuilder.new()
+
+export const getGovActionId = (wasm, govActionTxHashInHex, govActionIndex) =>
+ wasm.GovernanceActionId.new(getTransactionHashFromHex(wasm, govActionTxHashInHex), govActionIndex)
+
+export const getVoter = (wasm, dRepKeyHash) => wasm.Voter.new_drep(dRepKeyHash)
+
+export const getVotingProcedure = (wasm, votingChoice) => wasm.VotingProcedure.new(votingChoice)
diff --git a/src/utils/helpFunctions.js b/src/utils/helpFunctions.js
index 702376c..6621562 100644
--- a/src/utils/helpFunctions.js
+++ b/src/utils/helpFunctions.js
@@ -7,7 +7,7 @@ export const getBalance = async (api, wasm) => {
return adaValue
}
-export const getUTxOs = async (api, wasm, amountLovelaces, requestParam = {page: 0, limit: 5}) => {
+export const getUTxOs = async (api, wasm, amountLovelaces, requestParam = {page: 0, limit: 20}) => {
const utxos = []
const hexUtxos = await api.getUtxos(amountLovelaces, requestParam)
for (const hexUtxo of hexUtxos) {
@@ -64,3 +64,41 @@ export const getUnregPubStakeKey = async (api, wasm) => {
return stakeKeyHash
}
+
+export const getUsedAddress = async (api, wasm) => {
+ const requestParam = {page: 0, limit: 1}
+ const hexAddresses = await api.getUsedAddresses(requestParam)
+ const addresses = []
+ for (const hexAddr of hexAddresses) {
+ addresses.push(getBech32AddressFromHex(wasm, hexAddr))
+ }
+ return addresses[0]
+}
+
+export const getUnusedAddress = async (api, wasm) => {
+ const hexAddresses = await api.getUnusedAddresses()
+ const addresses = []
+ for (const hexAddr of hexAddresses) {
+ addresses.push(getBech32AddressFromHex(wasm, hexAddr))
+ }
+ return addresses[0]
+}
+
+const randomBytes = (count) => {
+ const result = Array(count)
+ for (let i = 0; i < count; ++i) {
+ result[i] = Math.floor(256 * Math.random())
+ }
+ return result
+}
+
+const toHexString = (byteArray) => {
+ return Array.from(byteArray, function (byte) {
+ return ('0' + (byte & 0xff).toString(16)).slice(-2)
+ }).join('')
+}
+
+export const getRandomHex = (bytes) => {
+ const byteArr = randomBytes(bytes)
+ return toHexString(byteArr)
+}
diff --git a/src/utils/networkConfig.js b/src/utils/networkConfig.js
new file mode 100644
index 0000000..c0041b2
--- /dev/null
+++ b/src/utils/networkConfig.js
@@ -0,0 +1,11 @@
+export const protocolParams = Object.freeze({
+ linearFee: {
+ minFeeA: '44',
+ minFeeB: '155381',
+ },
+ coinsPerUtxoWord: '34482',
+ poolDeposit: '500000000',
+ keyDeposit: '2000000',
+ maxValueSize: 5000,
+ maxTxSize: 16384,
+})