Skip to content

feat: drep update #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { ConfirmDRepUpdate } from '@lace/core';
import { SignTxData } from './types';
import { certificateInspectorFactory, drepIDasBech32FromHash } from './utils';
import { Wallet } from '@lace/cardano';

const { CertificateType } = Wallet.Cardano;

interface Props {
signTxData: SignTxData;
errorMessage?: string;
}

export const ConfirmDRepUpdateContainer = ({ signTxData, errorMessage }: Props): React.ReactElement => {
const { t } = useTranslation();
const certificate = certificateInspectorFactory<Wallet.Cardano.UpdateDelegateRepresentativeCertificate>(
CertificateType.UpdateDelegateRepresentative
)(signTxData.tx);

return (
<ConfirmDRepUpdate
dappInfo={signTxData.dappInfo}
metadata={{
drepId: drepIDasBech32FromHash(certificate.dRepCredential.hash),
hash: certificate.anchor?.dataHash,
url: certificate.anchor?.url
}}
translations={{
metadata: t('core.drepUpdate.metadata'),
labels: {
drepId: t('core.drepUpdate.drepId'),
hash: t('core.drepUpdate.hash'),
url: t('core.drepUpdate.url')
}
}}
errorMessage={errorMessage}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SignTxData } from './types';
import { ConfirmDRepRetirementContainer } from './ConfirmDRepRetirementContainer';
import { ConfirmVoteDelegationContainer } from './ConfirmVoteDelegationContainer';
import { VotingProceduresContainer } from './VotingProceduresContainer';
import { ConfirmDRepUpdateContainer } from './ConfirmDRepUpdateContainer';

interface Props {
txType?: TxType;
Expand All @@ -24,6 +25,9 @@ export const ConfirmTransactionContent = ({ txType, signTxData, errorMessage }:
if (txType === TxType.DRepRetirement) {
return <ConfirmDRepRetirementContainer signTxData={signTxData} errorMessage={errorMessage} />;
}
if (txType === TxType.DRepUpdate) {
return <ConfirmDRepUpdateContainer signTxData={signTxData} errorMessage={errorMessage} />;
}
if (txType === TxType.VoteDelegation) {
return <ConfirmVoteDelegationContainer signTxData={signTxData} errorMessage={errorMessage} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum TxType {
Burn = 'Burn',
DRepRegistration = 'DRepRegistration',
DRepRetirement = 'DRepRetirement',
DRepUpdate = 'DRepUpdate',
VoteDelegation = 'VoteDelegation',
VotingProcedures = 'VotingProcedures'
}
Expand All @@ -31,6 +32,10 @@ export const getTitleKey = (txType: TxType): string => {
return 'core.drepRetirement.title';
}

if (txType === TxType.DRepUpdate) {
return 'core.drepUpdate.title';
}

if (txType === TxType.VoteDelegation) {
return 'core.voteDelegation.title';
}
Expand Down Expand Up @@ -101,10 +106,11 @@ export const getTxType = (tx: Wallet.Cardano.Tx): TxType => {
votingProcedures: votingProceduresInspector,
dRepRegistration: certificateInspectorFactory(CertificateType.RegisterDelegateRepresentative),
dRepRetirement: certificateInspectorFactory(CertificateType.UnregisterDelegateRepresentative),
dRepUpdate: certificateInspectorFactory(CertificateType.UpdateDelegateRepresentative),
voteDelegation: certificateInspectorFactory(CertificateType.VoteDelegation)
});

const { minted, burned, dRepRegistration, dRepRetirement, voteDelegation, votingProcedures } = inspector(
const { minted, burned, dRepRegistration, dRepRetirement, dRepUpdate, voteDelegation, votingProcedures } = inspector(
tx as Wallet.Cardano.HydratedTx
);
const isMintTransaction = minted.length > 0;
Expand Down Expand Up @@ -134,6 +140,10 @@ export const getTxType = (tx: Wallet.Cardano.Tx): TxType => {
return TxType.VoteDelegation;
}

if (dRepUpdate) {
return TxType.DRepUpdate;
}

return TxType.Send;
};

Expand Down
7 changes: 7 additions & 0 deletions apps/browser-extension-wallet/src/lib/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,13 @@
"isOwnRetirement": "This is your DRep retirement.",
"isNotOwnRetirement": "The presented DRepID does not match your wallet's DRepID."
},
"drepUpdate": {
"title": "Confirm DRep update",
"metadata": "Metadata",
"drepId": "Drep ID",
"url": "URL",
"hash": "Hash"
},
"voteDelegation": {
"title": "Confirm vote delegation",
"metadata": "Metadata",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export * from '@ui/components/MnemonicWordsAutoComplete';
export * from '@ui/components/AddressCard';
export * from '@ui/components/ConfirmDRepRegistration';
export * from '@ui/components/ConfirmDRepRetirement';
export * from '@ui/components/ConfirmDRepUpdate';
export * from '@ui/components/ConfirmVoteDelegation';
export * from '@ui/components/VotingProcedures';
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { Meta, StoryObj } from '@storybook/react';

import { ConfirmDRepUpdate } from './ConfirmDRepUpdate';
import { ComponentProps } from 'react';

const meta: Meta<typeof ConfirmDRepUpdate> = {
title: 'ConfirmDRepUpdate',
component: ConfirmDRepUpdate,
parameters: {
layout: 'centered'
}
};

export default meta;
type Story = StoryObj<typeof ConfirmDRepUpdate>;

const data: ComponentProps<typeof ConfirmDRepUpdate> = {
dappInfo: {
logo: 'https://cdn.mint.handle.me/favicon.png',
name: 'Mint',
url: 'https://preprod.mint.handle.me'
},
translations: {
labels: {
drepId: 'Drep ID',
hash: 'Hash',
url: 'URL'
},
metadata: 'Metadata'
},
metadata: {
drepId: '65ge6g54g5dd5',
hash: '9bba8233cdd086f0325daba465d568a88970d42536f9e71e92a80d5922ded885',
url: 'https://github.com/raw/Ryun1/gov-metadata/main/governace-action/metadata.jsonldr1q99...uqvzlalu'
}
};

export const Overview: Story = {
args: {
...data
}
};

export const Empty: Story = {
args: {
...data,
metadata: {
drepId: '65ge6g54g5dd5'
}
}
};

export const WithError: Story = {
args: {
...data,
errorMessage: 'Something went wrong'
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { Box, Cell, Grid, TransactionSummary, Flex } from '@lace/ui';
import { DappInfo, DappInfoProps } from '../DappInfo';
import { ErrorPane } from '@lace/common';

interface Props {
dappInfo: Omit<DappInfoProps, 'className'>;
errorMessage?: string;
translations: {
labels: {
url: string;
hash: string;
drepId: string;
};
metadata: string;
};
metadata: {
url?: string;
hash?: string;
drepId: string;
};
}

export const ConfirmDRepUpdate = ({ dappInfo, errorMessage, translations, metadata }: Props): JSX.Element => (
<Flex h="$fill" flexDirection="column">
<Box mb={'$28'} mt={'$32'}>
<DappInfo {...dappInfo} />
</Box>
{errorMessage && (
<Box my={'$16'}>
<ErrorPane error={errorMessage} />
</Box>
)}
<Grid columns="$1" gutters="$20">
<Cell>
<TransactionSummary.Metadata label={translations.metadata} text="" />
</Cell>
{metadata.url && (
<Cell>
<TransactionSummary.Address label={translations.labels.url} address={metadata.url} />
</Cell>
)}
{metadata.hash && (
<Cell>
<TransactionSummary.Address label={translations.labels.hash} address={metadata.hash} />
</Cell>
)}
<Cell>
<TransactionSummary.Address label={translations.labels.drepId} address={metadata.drepId} />
</Cell>
</Grid>
</Flex>
);
1 change: 1 addition & 0 deletions packages/core/src/ui/components/ConfirmDRepUpdate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ConfirmDRepUpdate } from './ConfirmDRepUpdate';