Skip to content

Commit 8ead049

Browse files
author
Lucas Araujo
committed
feat: drep update
1 parent ead7fcb commit 8ead049

File tree

8 files changed

+175
-1
lines changed

8 files changed

+175
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { ConfirmDRepUpdate } from '@lace/core';
4+
import { SignTxData } from './types';
5+
import { certificateInspectorFactory, drepIDasBech32FromHash } from './utils';
6+
import { Wallet } from '@lace/cardano';
7+
8+
const { CertificateType } = Wallet.Cardano;
9+
10+
interface Props {
11+
signTxData: SignTxData;
12+
errorMessage?: string;
13+
}
14+
15+
export const ConfirmDRepUpdateContainer = ({ signTxData, errorMessage }: Props): React.ReactElement => {
16+
const { t } = useTranslation();
17+
const certificate = certificateInspectorFactory<Wallet.Cardano.UpdateDelegateRepresentativeCertificate>(
18+
CertificateType.UpdateDelegateRepresentative
19+
)(signTxData.tx);
20+
21+
return (
22+
<ConfirmDRepUpdate
23+
dappInfo={signTxData.dappInfo}
24+
metadata={{
25+
drepId: drepIDasBech32FromHash(certificate.dRepCredential.hash),
26+
hash: certificate.anchor?.dataHash,
27+
url: certificate.anchor?.url
28+
}}
29+
translations={{
30+
metadata: t('core.drepUpdate.metadata'),
31+
labels: {
32+
drepId: t('core.drepUpdate.drepId'),
33+
hash: t('core.drepUpdate.hash'),
34+
url: t('core.drepUpdate.url')
35+
}
36+
}}
37+
errorMessage={errorMessage}
38+
/>
39+
);
40+
};

apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/ConfirmTransactionContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SignTxData } from './types';
77
import { ConfirmDRepRetirementContainer } from './ConfirmDRepRetirementContainer';
88
import { ConfirmVoteDelegationContainer } from './ConfirmVoteDelegationContainer';
99
import { VotingProceduresContainer } from './VotingProceduresContainer';
10+
import { ConfirmDRepUpdateContainer } from './ConfirmDRepUpdateContainer';
1011

1112
interface Props {
1213
txType?: TxType;
@@ -24,6 +25,9 @@ export const ConfirmTransactionContent = ({ txType, signTxData, errorMessage }:
2425
if (txType === TxType.DRepRetirement) {
2526
return <ConfirmDRepRetirementContainer signTxData={signTxData} errorMessage={errorMessage} />;
2627
}
28+
if (txType === TxType.DRepUpdate) {
29+
return <ConfirmDRepUpdateContainer signTxData={signTxData} errorMessage={errorMessage} />;
30+
}
2731
if (txType === TxType.VoteDelegation) {
2832
return <ConfirmVoteDelegationContainer signTxData={signTxData} errorMessage={errorMessage} />;
2933
}

apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum TxType {
1818
Burn = 'Burn',
1919
DRepRegistration = 'DRepRegistration',
2020
DRepRetirement = 'DRepRetirement',
21+
DRepUpdate = 'DRepUpdate',
2122
VoteDelegation = 'VoteDelegation',
2223
VotingProcedures = 'VotingProcedures'
2324
}
@@ -31,6 +32,10 @@ export const getTitleKey = (txType: TxType): string => {
3132
return 'core.drepRetirement.title';
3233
}
3334

35+
if (txType === TxType.DRepUpdate) {
36+
return 'core.drepUpdate.title';
37+
}
38+
3439
if (txType === TxType.VoteDelegation) {
3540
return 'core.voteDelegation.title';
3641
}
@@ -101,10 +106,11 @@ export const getTxType = (tx: Wallet.Cardano.Tx): TxType => {
101106
votingProcedures: votingProceduresInspector,
102107
dRepRegistration: certificateInspectorFactory(CertificateType.RegisterDelegateRepresentative),
103108
dRepRetirement: certificateInspectorFactory(CertificateType.UnregisterDelegateRepresentative),
109+
dRepUpdate: certificateInspectorFactory(CertificateType.UpdateDelegateRepresentative),
104110
voteDelegation: certificateInspectorFactory(CertificateType.VoteDelegation)
105111
});
106112

107-
const { minted, burned, dRepRegistration, dRepRetirement, voteDelegation, votingProcedures } = inspector(
113+
const { minted, burned, dRepRegistration, dRepRetirement, dRepUpdate, voteDelegation, votingProcedures } = inspector(
108114
tx as Wallet.Cardano.HydratedTx
109115
);
110116
const isMintTransaction = minted.length > 0;
@@ -134,6 +140,10 @@ export const getTxType = (tx: Wallet.Cardano.Tx): TxType => {
134140
return TxType.VoteDelegation;
135141
}
136142

143+
if (dRepUpdate) {
144+
return TxType.DRepUpdate;
145+
}
146+
137147
return TxType.Send;
138148
};
139149

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,13 @@
11371137
"isOwnRetirement": "This is your DRep retirement.",
11381138
"isNotOwnRetirement": "The presented DRepID does not match your wallet's DRepID."
11391139
},
1140+
"drepUpdate": {
1141+
"title": "Confirm DRep update",
1142+
"metadata": "Metadata",
1143+
"drepId": "Drep ID",
1144+
"url": "URL",
1145+
"hash": "Hash"
1146+
},
11401147
"voteDelegation": {
11411148
"title": "Confirm vote delegation",
11421149
"metadata": "Metadata",

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export * from '@ui/components/MnemonicWordsAutoComplete';
3030
export * from '@ui/components/AddressCard';
3131
export * from '@ui/components/ConfirmDRepRegistration';
3232
export * from '@ui/components/ConfirmDRepRetirement';
33+
export * from '@ui/components/ConfirmDRepUpdate';
3334
export * from '@ui/components/ConfirmVoteDelegation';
3435
export * from '@ui/components/VotingProcedures';
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { ConfirmDRepUpdate } from './ConfirmDRepUpdate';
4+
import { ComponentProps } from 'react';
5+
6+
const meta: Meta<typeof ConfirmDRepUpdate> = {
7+
title: 'ConfirmDRepUpdate',
8+
component: ConfirmDRepUpdate,
9+
parameters: {
10+
layout: 'centered'
11+
}
12+
};
13+
14+
export default meta;
15+
type Story = StoryObj<typeof ConfirmDRepUpdate>;
16+
17+
const data: ComponentProps<typeof ConfirmDRepUpdate> = {
18+
dappInfo: {
19+
logo: 'https://cdn.mint.handle.me/favicon.png',
20+
name: 'Mint',
21+
url: 'https://preprod.mint.handle.me'
22+
},
23+
translations: {
24+
labels: {
25+
drepId: 'Drep ID',
26+
hash: 'Hash',
27+
url: 'URL'
28+
},
29+
metadata: 'Metadata'
30+
},
31+
metadata: {
32+
drepId: '65ge6g54g5dd5',
33+
hash: '9bba8233cdd086f0325daba465d568a88970d42536f9e71e92a80d5922ded885',
34+
url: 'https://raw.githubusercontent.com/Ryun1/gov-metadata/main/governace-action/metadata.jsonldr1q99...uqvzlalu'
35+
}
36+
};
37+
38+
export const Overview: Story = {
39+
args: {
40+
...data
41+
}
42+
};
43+
44+
export const Empty: Story = {
45+
args: {
46+
...data,
47+
metadata: {
48+
drepId: '65ge6g54g5dd5'
49+
}
50+
}
51+
};
52+
53+
export const WithError: Story = {
54+
args: {
55+
...data,
56+
errorMessage: 'Something went wrong'
57+
}
58+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import { Box, Cell, Grid, TransactionSummary, Flex } from '@lace/ui';
3+
import { DappInfo, DappInfoProps } from '../DappInfo';
4+
import { ErrorPane } from '@lace/common';
5+
6+
interface Props {
7+
dappInfo: Omit<DappInfoProps, 'className'>;
8+
errorMessage?: string;
9+
translations: {
10+
labels: {
11+
url: string;
12+
hash: string;
13+
drepId: string;
14+
};
15+
metadata: string;
16+
};
17+
metadata: {
18+
url?: string;
19+
hash?: string;
20+
drepId: string;
21+
};
22+
}
23+
24+
export const ConfirmDRepUpdate = ({ dappInfo, errorMessage, translations, metadata }: Props): JSX.Element => (
25+
<Flex h="$fill" flexDirection="column">
26+
<Box mb={'$28'} mt={'$32'}>
27+
<DappInfo {...dappInfo} />
28+
</Box>
29+
{errorMessage && (
30+
<Box my={'$16'}>
31+
<ErrorPane error={errorMessage} />
32+
</Box>
33+
)}
34+
<Grid columns="$1" gutters="$20">
35+
<Cell>
36+
<TransactionSummary.Metadata label={translations.metadata} text="" />
37+
</Cell>
38+
{metadata.url && (
39+
<Cell>
40+
<TransactionSummary.Address label={translations.labels.url} address={metadata.url} />
41+
</Cell>
42+
)}
43+
{metadata.hash && (
44+
<Cell>
45+
<TransactionSummary.Address label={translations.labels.hash} address={metadata.hash} />
46+
</Cell>
47+
)}
48+
<Cell>
49+
<TransactionSummary.Address label={translations.labels.drepId} address={metadata.drepId} />
50+
</Cell>
51+
</Grid>
52+
</Flex>
53+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ConfirmDRepUpdate } from './ConfirmDRepUpdate';

0 commit comments

Comments
 (0)