Skip to content

Commit c9b69a1

Browse files
authored
fix(extension): conway-era tx activities line items (#860)
* fix(extension): conway-era tx activiries line items * fix(extension): adjust tests * fix(extension): resolve pr comments
1 parent eecbe1d commit c9b69a1

File tree

43 files changed

+284
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+284
-192
lines changed

apps/browser-extension-wallet/src/lib/translations/en.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,26 @@
2424
"outgoing": "Sent",
2525
"sending": "Sending",
2626
"self": "Self Transaction",
27+
"vote": "Vote Signing",
28+
"HardForkInitiationAction": "Hard Fork Initiation Action",
29+
"NewConstitution": "New Constitution Action",
30+
"NoConfidence": "No Confidence Action",
31+
"ParameterChangeAction": "Parameter Change Action",
32+
"TreasuryWithdrawalsAction": "Treasury Withdrawals Action",
33+
"UpdateCommittee": "Update Committee Action",
34+
"InfoAction": "Info Action",
35+
"UpdateDelegateRepresentativeCertificate": "Update DRep",
36+
"StakeVoteDelegationCertificate": "Stake Vote Delegation Certificate",
37+
"StakeRegistrationDelegationCertificate": "Stake Registration Delegation Certificate",
38+
"VoteRegistrationDelegationCertificate": "Vote Registration Delegation Certificate",
39+
"StakeVoteRegistrationDelegationCertificate": "Stake Vote Registration Delegation Certificate",
40+
"ResignCommitteeColdCertificate": "Resign Committee",
41+
"AuthorizeCommitteeHotCertificate": "Authorise Committee",
2742
"RegisterDelegateRepresentativeCertificate": "DRep Registration",
2843
"UnregisterDelegateRepresentativeCertificate": "DRep De-Registration",
29-
"UpdateDelegateRepresentativeCertificate": "DRep Update",
30-
"ResignCommitteeColdCertificate": "Resign Committee",
31-
"StakeRegistrationDelegationCertificate": "Stake Key Registration & Delgation",
32-
"StakeVoteDelegationCertificate": "Stake Key Registration & DRep Delegation",
33-
"StakeVoteRegistrationDelegationCertificate": "Stake Key Registration, Delegation, & DRep Delegation",
34-
"VoteRegistrationDelegationCertificate": "Stake Key Registration & DRep Delegation",
35-
"AuthorizeCommitteeHotCertificate": "Authorize Committee",
3644
"VoteDelegationCertificate": "Vote Delegation",
37-
"vote": "Vote Signing",
38-
"submitProposal": "Governance Proposal"
45+
46+
"submitProposal": "Confirm Vote"
3947
},
4048
"certificates": {
4149
"headings": {

apps/browser-extension-wallet/src/stores/slices/activity-detail-slice.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { inspectTxValues } from '@src/utils/tx-inspection';
1717
import { firstValueFrom } from 'rxjs';
1818
import { getAssetsInformation } from '@src/utils/get-assets-information';
1919
import { MAX_POOLS_COUNT } from '@lace/staking';
20-
import { ActivityStatus, DelegationTransactionType, TransactionActivityType } from '@lace/core';
20+
import { ActivityStatus, DelegationActivityType, TransactionActivityType } from '@lace/core';
2121
import type { ActivityType } from '@lace/core';
2222
import { formatDate, formatTime } from '@src/utils/format-date';
2323
import {
@@ -65,11 +65,11 @@ const shouldIncludeFee = (
6565
delegationInfo: Wallet.Cardano.StakeDelegationCertificate[] | undefined
6666
) =>
6767
!(
68-
type === DelegationTransactionType.delegationRegistration ||
68+
type === DelegationActivityType.delegationRegistration ||
6969
// Existence of any (new) delegationInfo means that this "de-registration"
7070
// activity is accompanied by a "delegation" activity, which carries the fees.
7171
// However, fees should be shown if de-registration activity is standalone.
72-
(type === DelegationTransactionType.delegationDeregistration && !!delegationInfo?.length)
72+
(type === DelegationActivityType.delegationDeregistration && !!delegationInfo?.length)
7373
);
7474

7575
const getPoolInfos = async (poolIds: Wallet.Cardano.PoolId[], stakePoolProvider: Wallet.StakePoolProvider) => {
@@ -191,14 +191,14 @@ const buildGetActivityDetail =
191191
const deposit =
192192
// since one tx can be split into two (delegation, registration) actions,
193193
// ensure only the registration tx carries the deposit
194-
implicitCoin.deposit && type === DelegationTransactionType.delegationRegistration
194+
implicitCoin.deposit && type === DelegationActivityType.delegationRegistration
195195
? Wallet.util.lovelacesToAdaString(implicitCoin.deposit.toString())
196196
: undefined;
197197
const depositReclaimValue = Wallet.util.calculateDepositReclaim(implicitCoin);
198198
const depositReclaim =
199199
// since one tx can be split into two (delegation, de-registration) actions,
200200
// ensure only the de-registration tx carries the reclaimed deposit
201-
depositReclaimValue && type === DelegationTransactionType.delegationDeregistration
201+
depositReclaimValue && type === DelegationActivityType.delegationDeregistration
202202
? Wallet.util.lovelacesToAdaString(depositReclaimValue.toString())
203203
: undefined;
204204
const feeInAda = Wallet.util.lovelacesToAdaString(tx.body.fee.toString());
@@ -226,7 +226,7 @@ const buildGetActivityDetail =
226226
certificates: certificateTransformer(cardanoCoin, tx.body.certificates)
227227
};
228228

229-
if (type === DelegationTransactionType.delegation && delegationInfo) {
229+
if (type === DelegationActivityType.delegation && delegationInfo) {
230230
const pools = await getPoolInfos(
231231
delegationInfo.map(({ poolId }) => poolId),
232232
stakePoolProvider

apps/browser-extension-wallet/src/stores/slices/wallet-activities-slice.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
ActivityStatus,
2121
AssetActivityItemProps,
2222
AssetActivityListProps,
23-
DelegationTransactionType,
23+
DelegationActivityType,
2424
TransactionActivityType
2525
} from '@lace/core';
2626
import { CurrencyInfo, TxDirections } from '@src/types';
@@ -66,20 +66,20 @@ type MappedActivityListProps = Omit<AssetActivityListProps, 'items'> & {
6666
export type FetchWalletActivitiesReturn = Observable<Promise<MappedActivityListProps[]>>;
6767

6868
type DelegationActivityItemProps = Omit<ExtendedActivityProps, 'type'> & {
69-
type: DelegationTransactionType;
69+
type: DelegationActivityType;
7070
};
7171

7272
const isDelegationActivity = (activity: ExtendedActivityProps): activity is DelegationActivityItemProps =>
73-
activity.type in DelegationTransactionType;
73+
activity.type in DelegationActivityType;
7474

7575
const getDelegationAmount = (activity: DelegationActivityItemProps) => {
7676
const fee = new BigNumber(Number.parseFloat(activity.fee));
7777

78-
if (activity.type === DelegationTransactionType.delegationRegistration) {
78+
if (activity.type === DelegationActivityType.delegationRegistration) {
7979
return fee.plus(activity.deposit);
8080
}
8181

82-
if (activity.type === DelegationTransactionType.delegationDeregistration) {
82+
if (activity.type === DelegationActivityType.delegationDeregistration) {
8383
return new BigNumber(activity.depositReclaim).minus(fee);
8484
}
8585

apps/browser-extension-wallet/src/utils/__tests__/inspectTxType.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,9 @@ describe('testing tx-inspection utils', () => {
428428
rewardAccount: REWARD_ACCOUNT,
429429
// eslint-disable-next-line unicorn/no-null
430430
anchor: null,
431-
governanceAction: {} as Wallet.Cardano.GovernanceAction,
431+
governanceAction: {
432+
__typename: Wallet.Cardano.GovernanceActionType.parameter_change_action
433+
} as Wallet.Cardano.GovernanceAction,
432434
deposit: BigInt(1)
433435
}
434436
]
@@ -438,7 +440,7 @@ describe('testing tx-inspection utils', () => {
438440
{ address: ADDRESS_1, rewardAccount: REWARD_ACCOUNT }
439441
] as Wallet.KeyManagement.GroupedAddress[]
440442
});
441-
expect(result).toEqual('submitProposal');
443+
expect(result).toEqual('ParameterChangeAction');
442444
});
443445
});
444446
});

apps/browser-extension-wallet/src/utils/mocks/certificates.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export const mockConwayCertificates: Partial<
3030
dRepCredential: CREDENTIAL,
3131
anchor: null
3232
},
33-
[ConwayEraCertificatesTypes.VoteDelegation]: {
34-
__typename: Wallet.Cardano.CertificateType.VoteDelegation,
35-
dRep: CREDENTIAL,
36-
stakeCredential: CREDENTIAL
37-
},
3833
[ConwayEraCertificatesTypes.StakeVoteDelegation]: {
3934
__typename: Wallet.Cardano.CertificateType.StakeVoteDelegation,
4035
stakeCredential: CREDENTIAL,

apps/browser-extension-wallet/src/utils/mocks/raw-transactions.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,3 @@ export const drepRetirementTx: Wallet.Cardano.HydratedTx = {
7171
certificates: [mockConwayCertificates[ConwayEraCertificatesTypes.UnregisterDelegateRepresentative]]
7272
}
7373
};
74-
75-
export const voteDelegationTx: Wallet.Cardano.HydratedTx = {
76-
...tx,
77-
body: {
78-
...tx.body,
79-
certificates: [mockConwayCertificates[ConwayEraCertificatesTypes.VoteDelegation]]
80-
}
81-
};

apps/browser-extension-wallet/src/utils/tx-inspection.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import {
1212
import { Wallet } from '@lace/cardano';
1313
import {
1414
ActivityType,
15-
DelegationTransactionType,
15+
DelegationActivityType,
1616
TransactionActivityType,
1717
ConwayEraGovernanceActions,
18-
ConwayEraCertificatesTypes
18+
ConwayEraCertificatesTypes,
19+
Cip1694GovernanceActivityType
1920
} from '@lace/core';
2021
import { TxDirection, TxDirections } from '@src/types';
2122

@@ -60,8 +61,6 @@ const governanceCertificateInspection = (
6061
return ConwayEraCertificatesTypes.UnregisterDelegateRepresentative;
6162
case signedCertificateTypenames.includes(CertificateType.UpdateDelegateRepresentative):
6263
return ConwayEraCertificatesTypes.UpdateDelegateRepresentative;
63-
case signedCertificateTypenames.includes(CertificateType.VoteDelegation):
64-
return ConwayEraCertificatesTypes.VoteDelegation;
6564
case signedCertificateTypenames.includes(CertificateType.StakeVoteDelegation):
6665
return ConwayEraCertificatesTypes.StakeVoteDelegation;
6766
case signedCertificateTypenames.includes(CertificateType.StakeRegistrationDelegation):
@@ -77,6 +76,28 @@ const governanceCertificateInspection = (
7776
}
7877
};
7978

79+
// Assumes single procedure only
80+
export const cip1694GovernanceActionsInspection = (
81+
procedure: Wallet.Cardano.ProposalProcedure
82+
): Cip1694GovernanceActivityType => {
83+
switch (procedure.governanceAction.__typename) {
84+
case Wallet.Cardano.GovernanceActionType.parameter_change_action:
85+
return Cip1694GovernanceActivityType.ParameterChangeAction;
86+
case Wallet.Cardano.GovernanceActionType.hard_fork_initiation_action:
87+
return Cip1694GovernanceActivityType.HardForkInitiationAction;
88+
case Wallet.Cardano.GovernanceActionType.treasury_withdrawals_action:
89+
return Cip1694GovernanceActivityType.TreasuryWithdrawalsAction;
90+
case Wallet.Cardano.GovernanceActionType.no_confidence:
91+
return Cip1694GovernanceActivityType.NoConfidence;
92+
case Wallet.Cardano.GovernanceActionType.update_committee:
93+
return Cip1694GovernanceActivityType.UpdateCommittee;
94+
case Wallet.Cardano.GovernanceActionType.new_constitution:
95+
return Cip1694GovernanceActivityType.NewConstitution;
96+
case Wallet.Cardano.GovernanceActionType.info_action:
97+
return Cip1694GovernanceActivityType.InfoAction;
98+
}
99+
};
100+
80101
const getWalletAccounts = (walletAddresses: Wallet.KeyManagement.GroupedAddress[]) =>
81102
walletAddresses.reduce(
82103
(acc, curr) => ({
@@ -145,17 +166,17 @@ export const inspectTxType = ({
145166
if (inspectionProperties.sent.inputs.length > 0 || withRewardsWithdrawal) {
146167
switch (true) {
147168
case !!inspectionProperties.delegation[0]?.poolId:
148-
return DelegationTransactionType.delegation;
169+
return DelegationActivityType.delegation;
149170
case inspectionProperties.stakeKeyRegistration.length > 0:
150-
return DelegationTransactionType.delegationRegistration;
171+
return DelegationActivityType.delegationRegistration;
151172
case inspectionProperties.stakeKeyDeregistration.length > 0:
152-
return DelegationTransactionType.delegationDeregistration;
173+
return DelegationActivityType.delegationDeregistration;
153174
// Voting procedures take priority over proposals
154175
// TODO: use proper inspector when available on sdk side (LW-9569)
155176
case tx.body.votingProcedures?.length > 0:
156177
return ConwayEraGovernanceActions.vote;
157178
case tx.body.proposalProcedures?.length > 0:
158-
return ConwayEraGovernanceActions.submitProposal;
179+
return cip1694GovernanceActionsInspection(tx.body.proposalProcedures[0]);
159180
case inspectionProperties.selfTransaction:
160181
return TransactionActivityType.self;
161182
default:

apps/browser-extension-wallet/src/views/browser-view/features/activity/components/ActivityDetail.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useTranslate,
1212
RewardsDetails,
1313
TransactionActivityType,
14-
DelegationTransactionType
14+
DelegationActivityType
1515
} from '@lace/core';
1616
import type { ActivityType } from '@lace/core';
1717
import { PriceResult } from '@hooks';
@@ -80,9 +80,8 @@ interface ActivityDetailProps {
8080
}
8181

8282
const getTypeLabel = (type: ActivityType, t: ReturnType<typeof useTranslate>['t']) => {
83-
if (type === DelegationTransactionType.delegationRegistration) return t('package.core.activityDetails.registration');
84-
if (type === DelegationTransactionType.delegationDeregistration)
85-
return t('package.core.activityDetails.deregistration');
83+
if (type === DelegationActivityType.delegationRegistration) return t('package.core.activityDetails.registration');
84+
if (type === DelegationActivityType.delegationDeregistration) return t('package.core.activityDetails.deregistration');
8685
if (type === TransactionActivityType.incoming) return t('package.core.activityDetails.received');
8786
if (type === TransactionActivityType.outgoing) return t('package.core.activityDetails.sent');
8887
return t(`package.core.activityDetails.${type}`);

apps/browser-extension-wallet/src/views/browser-view/features/activity/components/TransactionDetailsProxy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ReactElement, useMemo } from 'react';
2-
import { ActivityStatus, DelegationTransactionType, TransactionDetails } from '@lace/core';
2+
import { ActivityStatus, DelegationActivityType, TransactionDetails } from '@lace/core';
33
import { AddressListType, getTransactionData } from './ActivityDetail';
44
import { useWalletStore } from '@src/stores';
55
import { useAnalyticsContext, useExternalLinkOpener } from '@providers';
@@ -37,7 +37,7 @@ export const TransactionDetailsProxy = withAddressBookContext(
3737
return `${CEXPLORER_BASE_URL[environmentName]}/${CEXPLORER_URL_PATHS.Tx}`;
3838
}, [CEXPLORER_BASE_URL, CEXPLORER_URL_PATHS.Tx, environmentName]);
3939
const getHeaderDescription = () => {
40-
if (activityInfo.type === DelegationTransactionType.delegation) return '1 token';
40+
if (activityInfo.type === DelegationActivityType.delegation) return '1 token';
4141
return ` (${activityInfo?.assetAmount})`;
4242
};
4343
const isIncomingTransaction = direction === TxDirections.Incoming;

apps/browser-extension-wallet/src/views/browser-view/features/activity/helpers/common-tx-transformer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getTransactionTotalAmount } from '@src/utils/get-transaction-total-amou
77
import type { TransformedActivity, TransformedTransactionActivity } from './types';
88
import {
99
ActivityStatus,
10-
DelegationTransactionType,
10+
DelegationActivityType,
1111
TxDetails,
1212
TxDetailsCertificateTitles,
1313
TxDetailsVotingProceduresTitles,
@@ -54,13 +54,13 @@ const splitDelegationTx = (tx: TransformedActivity): TransformedTransactionActiv
5454
return [
5555
{
5656
...tx,
57-
type: DelegationTransactionType.delegation,
57+
type: DelegationActivityType.delegation,
5858
// Deposit already shown in the delegationRegistration
5959
deposit: undefined
6060
},
6161
{
6262
...tx,
63-
type: DelegationTransactionType.delegationRegistration,
63+
type: DelegationActivityType.delegationRegistration,
6464
// Let registration show just the deposit,
6565
// and the other transaction show fee to avoid duplicity
6666
fee: '0'
@@ -70,13 +70,13 @@ const splitDelegationTx = (tx: TransformedActivity): TransformedTransactionActiv
7070
return [
7171
{
7272
...tx,
73-
type: DelegationTransactionType.delegation,
73+
type: DelegationActivityType.delegation,
7474
// Reclaimed deposit already shown in the delegationDeregistration
7575
depositReclaim: undefined
7676
},
7777
{
7878
...tx,
79-
type: DelegationTransactionType.delegationDeregistration,
79+
type: DelegationActivityType.delegationDeregistration,
8080
// Let de-registration show just the returned deposit,
8181
// and the other transaction show fee to avoid duplicity
8282
fee: '0'
@@ -87,7 +87,7 @@ const splitDelegationTx = (tx: TransformedActivity): TransformedTransactionActiv
8787
return [
8888
{
8989
...tx,
90-
type: DelegationTransactionType.delegation
90+
type: DelegationActivityType.delegation
9191
}
9292
];
9393
};
@@ -184,7 +184,7 @@ export const txTransformer = async ({
184184
// SDK Ticket LW-8767 should fix the type of Input in TxInFlight to contain the address
185185
const type = inspectTxType({ walletAddresses, tx: tx as unknown as Wallet.Cardano.HydratedTx });
186186

187-
if (type === DelegationTransactionType.delegation) {
187+
if (type === DelegationActivityType.delegation) {
188188
return splitDelegationTx(baseTransformedActivity);
189189
}
190190

0 commit comments

Comments
 (0)