Skip to content

Commit

Permalink
refactor: fix ts null checks errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed Nov 25, 2024
1 parent 94f8913 commit 14263c6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
5 changes: 1 addition & 4 deletions packages/common/src/ui/hooks/useObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { NEVER, Observable } from 'rxjs';
* @returns latest emitted value of the observable; undefined if observable is undefined or hasn't emitted yet
*/
export const useObservable = <T>(observable: Observable<T> | undefined, defaultValue?: T): T => {
const [boundObservable] = useMemo(
() => (defaultValue !== undefined ? bind<T>(observable || NEVER, defaultValue) : bind<T>(observable || NEVER)),
[observable, defaultValue]
);
const [boundObservable] = useMemo(() => bind<T>(observable || NEVER, defaultValue as T), [observable, defaultValue]);
return boundObservable();
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type RewardsInfo = {

export interface RewardsDetailsProps {
name: string;
headerDescription: string;
headerDescription?: string;
status: ActivityStatus.SPENDABLE;
includedDate: string;
includedTime: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface OutputSummaryProps {
list: SentAssetsList;
recipientAddress: string;
recipientName?: string;
translations: TranslationsFor<'recipientAddress' | 'sending'>;
translations?: TranslationsFor<'recipientAddress' | 'sending'>;
ownAddresses?: string[];
}

Expand All @@ -31,14 +31,14 @@ export const OutputSummary = ({
return (
<div className={styles.container} data-testid="output-summary-container">
<RowContainer data-testid="output-summary-row">
{renderLabel({ label: translations.sending, dataTestId: 'output-summary-sending-title' })}
{renderLabel({ label: translations?.sending ?? '', dataTestId: 'output-summary-sending-title' })}
<div className={styles.assetList} data-testid="output-summary-asset-list">
{renderSentAssets(list)}
</div>
</RowContainer>

<RowContainer>
{renderLabel({ label: translations.recipientAddress, dataTestId: 'output-summary-recipient-title' })}
{renderLabel({ label: translations?.recipientAddress ?? '', dataTestId: 'output-summary-recipient-title' })}
<Flex className={styles.recipient} flexDirection="column">
{recipientName && (
<Box mb="$4" w="$fill">
Expand Down
73 changes: 39 additions & 34 deletions packages/core/src/ui/utils/governance-action.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable complexity */
/* eslint-disable sonarjs/cognitive-complexity */
import { Cardano } from '@cardano-sdk/core';
import { Wallet } from '@lace/cardano';
import { formatPercentages } from '@lace/common';
Expand Down Expand Up @@ -84,38 +86,38 @@ export const getParameterChangeActionViewData = ({
},
protocolParamUpdate: {
maxTxExUnits: {
memory: maxExecutionUnitsPerTransaction?.memory?.toString(),
step: maxExecutionUnitsPerTransaction?.steps?.toString()
memory: maxExecutionUnitsPerTransaction?.memory?.toString() ?? '',
step: maxExecutionUnitsPerTransaction?.steps?.toString() ?? ''
},
maxBlockExUnits: {
memory: maxExecutionUnitsPerBlock?.memory?.toString(),
step: maxExecutionUnitsPerBlock?.steps?.toString()
memory: maxExecutionUnitsPerBlock?.memory?.toString() ?? '',
step: maxExecutionUnitsPerBlock?.steps?.toString() ?? ''
},
networkGroup: {
maxBBSize: maxBlockBodySize?.toString(),
maxTxSize: maxTxSize?.toString(),
maxBHSize: maxBlockHeaderSize?.toString(),
maxValSize: maxValueSize?.toString(),
maxCollateralInputs: maxCollateralInputs?.toString()
maxBBSize: maxBlockBodySize?.toString() ?? '',
maxTxSize: maxTxSize?.toString() ?? '',
maxBHSize: maxBlockHeaderSize?.toString() ?? '',
maxValSize: maxValueSize?.toString() ?? '',
maxCollateralInputs: maxCollateralInputs?.toString() ?? ''
},
economicGroup: {
minFeeA: minFeeCoefficient?.toString(),
minFeeB: minFeeConstant?.toString(),
keyDeposit: stakeKeyDeposit?.toString(),
poolDeposit: poolDeposit?.toString(),
rho: monetaryExpansion,
tau: treasuryExpansion,
minPoolCost: minPoolCost?.toString(),
coinsPerUTxOByte: coinsPerUtxoByte?.toString(),
minFeeA: minFeeCoefficient?.toString() ?? '',
minFeeB: minFeeConstant?.toString() ?? '',
keyDeposit: stakeKeyDeposit?.toString() ?? '',
poolDeposit: poolDeposit?.toString() ?? '',
rho: monetaryExpansion ?? '',
tau: treasuryExpansion ?? '',
minPoolCost: minPoolCost?.toString() ?? '',
coinsPerUTxOByte: coinsPerUtxoByte?.toString() ?? '',
price: {
memory: prices?.memory?.toString(),
step: prices?.steps?.toString()
memory: prices?.memory?.toString() ?? '',
step: prices?.steps?.toString() ?? ''
}
},
technicalGroup: {
a0: poolInfluence,
eMax: poolRetirementEpochBound?.toString(),
nOpt: desiredNumberOfPools?.toString(),
a0: poolInfluence ?? '',
eMax: poolRetirementEpochBound?.toString() ?? '',
nOpt: desiredNumberOfPools?.toString() ?? '',
costModels: {
PlutusV1: Object.entries(costModels?.get(Cardano.PlutusLanguageVersion.V1) || {}).reduce(
(acc, cur) => ({ ...acc, [cur[0]]: cur[1] }),
Expand All @@ -126,21 +128,24 @@ export const getParameterChangeActionViewData = ({
{}
)
},
collateralPercentage: collateralPercentage?.toString()
collateralPercentage: collateralPercentage?.toString() ?? ''
},
governanceGroup: {
govActionLifetime: governanceActionValidityPeriod?.toString(),
govActionDeposit: governanceActionDeposit?.toString(),
drepDeposit: dRepDeposit?.toString(),
drepActivity: dRepInactivityPeriod?.toString(),
ccMinSize: minCommitteeSize?.toString(),
ccMaxTermLength: committeeTermLimit?.toString(),
govActionLifetime: governanceActionValidityPeriod?.toString() ?? '',
govActionDeposit: governanceActionDeposit?.toString() ?? '',
drepDeposit: dRepDeposit?.toString() ?? '',
drepActivity: dRepInactivityPeriod?.toString() ?? '',
ccMinSize: minCommitteeSize?.toString() ?? '',
ccMaxTermLength: committeeTermLimit?.toString() ?? '',
dRepVotingThresholds: {
...(dRepVotingThresholds?.motionNoConfidence && {
motionNoConfidence: formatPercentages(
dRepVotingThresholds.motionNoConfidence.numerator / dRepVotingThresholds.motionNoConfidence.denominator
)
}),
...(dRepVotingThresholds?.motionNoConfidence
? {
motionNoConfidence: formatPercentages(
dRepVotingThresholds.motionNoConfidence.numerator /
dRepVotingThresholds.motionNoConfidence.denominator
)
}
: { motionNoConfidence: '' }),
committeeNormal: convertFractionToPercentage(
dRepVotingThresholds?.committeeNormal.numerator,
dRepVotingThresholds?.committeeNormal.denominator
Expand Down

0 comments on commit 14263c6

Please sign in to comment.