Skip to content

Commit

Permalink
refactor(core): renaming functions and mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
tommayeliog committed May 7, 2024
1 parent 750425b commit 4ed67ad
Show file tree
Hide file tree
Showing 35 changed files with 253 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const VotingProceduresContainer = (): React.ReactElement => {
<Box mb={'$28'} mt={'$32'}>
<DappInfo {...dappInfo} />
</Box>
<VotingProcedures data={Wallet.util.votingProceduresRawToViewMap(votingProcedures, explorerBaseUrl)} />
<VotingProcedures
data={votingProcedures.map((votingProcedure) =>
Wallet.util.mapVotingProceduresToView(votingProcedure, explorerBaseUrl)
)}
/>
</Flex>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Wallet } from '@lace/cardano';
import { HardForkInitiationAction, hardForkInitiationActionDataMap } from '@lace/core';
import { HardForkInitiationAction, getHardForkInitiationActionViewData } from '@lace/core';
import { useWalletStore } from '@src/stores';
import { useCexplorerBaseUrl } from '../hooks';

Expand All @@ -23,7 +23,7 @@ export const HardForkInitiationActionContainer = ({

const explorerBaseUrl = useCexplorerBaseUrl();

const data = hardForkInitiationActionDataMap({
const data = getHardForkInitiationActionViewData({
anchor,
cardanoCoin,
deposit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Wallet } from '@lace/cardano';
import { InfoAction, infoActionDataMap } from '@lace/core';
import { InfoAction, getInfoActionViewData } from '@lace/core';
import { useCexplorerBaseUrl } from '../hooks';

interface Props {
Expand All @@ -10,7 +10,7 @@ interface Props {
export const InfoActionContainer = ({ anchor }: Props): React.ReactElement => {
const explorerBaseUrl = useCexplorerBaseUrl();

const data = infoActionDataMap({ anchor, explorerBaseUrl });
const data = getInfoActionViewData({ anchor, explorerBaseUrl });

return <InfoAction data={data} />;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Wallet } from '@lace/cardano';
import { NewConstitutionAction, newConstitutionActionDataMap } from '@lace/core';
import { NewConstitutionAction, getNewConstitutionActionViewData } from '@lace/core';
import { useWalletStore } from '@src/stores';
import { useCexplorerBaseUrl } from '../hooks';

Expand All @@ -23,7 +23,7 @@ export const NewConstitutionActionContainer = ({

const explorerBaseUrl = useCexplorerBaseUrl();

const data = newConstitutionActionDataMap({
const data = getNewConstitutionActionViewData({
anchor,
cardanoCoin,
deposit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Wallet } from '@lace/cardano';
import { NoConfidenceAction, noConfidenceActionDataMap } from '@lace/core';
import { NoConfidenceAction, getNoConfidenceActionViewData } from '@lace/core';
import { useWalletStore } from '@src/stores';
import { useCexplorerBaseUrl } from '../hooks';

Expand All @@ -23,7 +23,7 @@ export const NoConfidenceActionContainer = ({

const explorerBaseUrl = useCexplorerBaseUrl();

const data = noConfidenceActionDataMap({
const data = getNoConfidenceActionViewData({
anchor,
cardanoCoin,
deposit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable unicorn/no-array-reduce */
import React from 'react';
import { Wallet } from '@lace/cardano';
import { ParameterChangeAction, parameterChangeActionDataMap } from '@lace/core';
import { ParameterChangeAction, getParameterChangeActionViewData } from '@lace/core';
import { useWalletStore } from '@src/stores';

import { useCexplorerBaseUrl } from '../../hooks';
Expand All @@ -25,9 +25,7 @@ export const ParameterChangeActionContainer = ({

const explorerBaseUrl = useCexplorerBaseUrl();

// TODO: consider encapsulating it inside the component itself, check if all the translations have the fallback to the parent int provider (LW-9920)

const data = parameterChangeActionDataMap({
const data = getParameterChangeActionViewData({
governanceAction,
deposit,
rewardAccount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Wallet } from '@lace/cardano';
import { TreasuryWithdrawalsAction, treasuryWithdrawalsActionDataMap } from '@lace/core';
import { TreasuryWithdrawalsAction, getTreasuryWithdrawalsActionViewData } from '@lace/core';
import { useWalletStore } from '@src/stores';
import { useCexplorerBaseUrl } from '../hooks';

Expand All @@ -23,7 +23,7 @@ export const TreasuryWithdrawalsActionContainer = ({

const explorerBaseUrl = useCexplorerBaseUrl();

const data = treasuryWithdrawalsActionDataMap({
const data = getTreasuryWithdrawalsActionViewData({
anchor,
cardanoCoin,
deposit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Wallet } from '@lace/cardano';
import { UpdateCommitteeAction, updateCommitteeActionDataMap } from '@lace/core';
import { UpdateCommitteeAction, getUpdateCommitteeActionViewData } from '@lace/core';
import { useWalletStore } from '@src/stores';
import { useCexplorerBaseUrl } from '../hooks';

Expand All @@ -22,7 +22,7 @@ export const UpdateCommitteeActionContainer = ({
} = useWalletStore();

const explorerBaseUrl = useCexplorerBaseUrl();
const data = updateCommitteeActionDataMap({
const data = getUpdateCommitteeActionViewData({
anchor,
cardanoCoin,
deposit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const TransactionDetailsProxy = withAddressBookContext(
collateral={collateral}
chainNetworkId={currentChain.networkId}
cardanoCoin={cardanoCoin}
explorerBaseUrl={explorerBaseUrl} // test for network switch
explorerBaseUrl={explorerBaseUrl}
/>
);
}
Expand Down
51 changes: 25 additions & 26 deletions packages/cardano/src/wallet/util/voter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getVote = (vote: Cardano.Vote): VotesEnum => {
}
};

type VotingProceduresView = {
type VotingProcedureView = {
voter: {
type: string;
dRepId?: string;
Expand All @@ -66,33 +66,32 @@ type VotingProceduresView = {
} | null;
};
}[];
}[];
};

export const votingProceduresRawToViewMap = (
votingProcedures: Cardano.VotingProcedures,
export const mapVotingProceduresToView = (
votingProcedure: Cardano.VotingProcedures[number],
explorerBaseUrl: string
): VotingProceduresView =>
votingProcedures.map((votingProcedure) => {
const voterType = getVoterType(votingProcedure.voter.__typename);
): VotingProcedureView => {
const voterType = getVoterType(votingProcedure.voter.__typename);

return {
voter: {
type: voterType,
dRepId: getDRepId(votingProcedure.voter)
return {
voter: {
type: voterType,
dRepId: getDRepId(votingProcedure.voter)
},
votes: votingProcedure.votes.map((vote) => ({
actionId: {
index: vote.actionId.actionIndex,
txHash: vote.actionId.id.toString(),
txHashUrl: `${explorerBaseUrl}/${vote.actionId.id}`
},
votes: votingProcedure.votes.map((vote) => ({
actionId: {
index: vote.actionId.actionIndex,
txHash: vote.actionId.id.toString(),
txHashUrl: `${explorerBaseUrl}/${vote.actionId.id}`
},
votingProcedure: {
vote: getVote(vote.votingProcedure.vote),
anchor: !!vote.votingProcedure.anchor && {
url: vote.votingProcedure.anchor.url,
hash: vote.votingProcedure.anchor.dataHash.toString()
}
votingProcedure: {
vote: getVote(vote.votingProcedure.vote),
anchor: !!vote.votingProcedure.anchor && {
url: vote.votingProcedure.anchor.url,
hash: vote.votingProcedure.anchor.dataHash.toString()
}
}))
};
});
}
}))
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ export const TransactionDetails = ({
const isSending = status === ActivityStatus.PENDING;
const isSuccess = status === ActivityStatus.SUCCESS;

// TODO: do we need this?
// const renderAnchorHashDetails = (url: string) => (
// <div className={styles.txLink} onClick={() => openExternalLink(url)}>
// {url}
// </div>
// );

const getCollateralStatus = (): CollateralStatus => {
switch (status) {
case ActivityStatus.SPENDABLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ export const CertificateView = ({
/>
);
default:
console.error('Not supported certificate:', certificate);
throw new Error(`Not supported certificate: ${certificate.__typename}`);
}

console.debug(`unknown certificate: ${certificate.__typename}`);
return <></>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const TxDetailsCertificates = ({
}: TxDetailsCertificatesProps): React.ReactElement => {
const { t } = useTranslate();

// metadata copy
return (
<TxDetailsGroup title={t('core.activityDetails.certificates')} testId="certificates" withSeparatorLine>
{certificates.map((cert, index) => (
Expand Down

This file was deleted.

0 comments on commit 4ed67ad

Please sign in to comment.