Skip to content
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
4 changes: 2 additions & 2 deletions apps/browser-extension-wallet/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DEFAULT_CHAIN=Mainnet
WALLET_SYNC_TIMEOUT_IN_SEC=60
WALLET_INTERVAL_IN_SEC=30
DROP_CONSOLE_IN_PRODUCTION=false
AVAILABLE_CHAINS=Preprod,Preview,Mainnet,Sanchonet
AVAILABLE_CHAINS=Preprod,Preview,Mainnet
ADA_PRICE_POLLING_IN_SEC=60
TOKEN_PRICE_POLLING_IN_SEC=300
SAVED_PRICE_DURATION_IN_MINUTES=720
Expand Down Expand Up @@ -75,7 +75,7 @@ ADA_HANDLE_URL_MAINNET=https://api.handle.me
ADA_HANDLE_URL_PREVIEW=https://preview.api.handle.me
ADA_HANDLE_URL_PREPROD=https://preprod.api.handle.me
# TODO: update this with a valid sanchonet url
ADA_HANDLE_URL_SANCHONET=https://preprod.api.handle.me
ADA_HANDLE_URL_SANCHONET=

# Manifest.json
LACE_EXTENSION_KEY=gafhhkghbfjjkeiendhlofajokpaflmk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { Wallet } from '@lace/cardano';

export const ADA_HANDLE_POLICY_ID = Wallet.ADA_HANDLE_POLICY_ID;
export const isAdaHandleEnabled = process.env.USE_ADA_HANDLE === 'true';
export const HANDLE_SERVER_URLS: Record<Cardano.NetworkMagics, string> = {
export const HANDLE_SERVER_URLS: Record<Exclude<Cardano.NetworkMagics, Cardano.NetworkMagics.Sanchonet>, string> = {
[Cardano.NetworkMagics.Mainnet]: 'https://api.handle.me',
[Cardano.NetworkMagics.Preprod]: 'https://preprod.api.handle.me',
[Cardano.NetworkMagics.Preview]: 'https://preview.api.handle.me',
// TODO: update once there's a valid sanchonet version available
[Cardano.NetworkMagics.Sanchonet]: 'https://sanchonet.api.handle.me'
[Cardano.NetworkMagics.Preview]: 'https://preview.api.handle.me'
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ interface Props {

export const ConfirmVoteDelegationContainer = ({ signTxData, errorMessage }: Props): React.ReactElement => {
const { t } = useTranslation();
const certificate = certificateInspectorFactory<Wallet.Cardano.VoteDelegationCertificate>(
const { dRep } = certificateInspectorFactory<Wallet.Cardano.VoteDelegationCertificate>(
CertificateType.VoteDelegation
)(signTxData.tx);
const dRep = certificate.dRep;

return (
<ConfirmVoteDelegation
dappInfo={signTxData.dappInfo}
metadata={{
alwaysAbstain: Wallet.Cardano.isDRepAlwaysAbstain(dRep),
alwaysNoConfidence: Wallet.Cardano.isDRepAlwaysNoConfidence(dRep),
...(Wallet.Cardano.isDRepCredential(dRep) ? { drepId: drepIDasBech32FromHash(dRep.hash) } : {})
...(Wallet.Cardano.isDRepCredential(dRep) && { drepId: drepIDasBech32FromHash(dRep.hash) })
}}
translations={{
metadata: t('core.voteDelegation.metadata'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,41 @@ interface Props {
errorMessage?: string;
}

export const getVoterType = (voterType: Wallet.Cardano.VoterType): 'Constitutional Committee' | 'SPO' | 'DRep' => {
export enum VoterType {
CONSTITUTIONAL_COMMITTEE = 'constitutionalCommittee',
SPO = 'spo',
DREP = 'drep'
}

export const getVoterType = (voterType: Wallet.Cardano.VoterType): VoterType => {
switch (voterType) {
case Wallet.Cardano.VoterType.ccHotKeyHash:
case Wallet.Cardano.VoterType.ccHotScriptHash:
return 'Constitutional Committee';
return VoterType.CONSTITUTIONAL_COMMITTEE;
case Wallet.Cardano.VoterType.stakePoolKeyHash:
return 'SPO';
return VoterType.SPO;
case Wallet.Cardano.VoterType.dRepKeyHash:
case Wallet.Cardano.VoterType.dRepScriptHash:
default:
return 'DRep';
return VoterType.DREP;
}
};

export const getVote = (vote: Wallet.Cardano.Vote): string => {
export enum Votes {
YES = 'yes',
NO = 'no',
ABSTAIN = 'abstain'
}

export const getVote = (vote: Wallet.Cardano.Vote): Votes => {
switch (vote) {
case Wallet.Cardano.Vote.yes:
return 'Yes';
return Votes.YES;
case Wallet.Cardano.Vote.no:
return 'No';
return Votes.NO;
case Wallet.Cardano.Vote.abstain:
default:
return 'Abstain';
return Votes.ABSTAIN;
}
};

Expand All @@ -56,12 +68,12 @@ export const VotingProceduresContainer = ({ signTxData, errorMessage }: Props):
const voterType = getVoterType(votingProcedure.voter.__typename);

const drepId =
voterType === 'DRep'
voterType === VoterType.DREP
? drepIDasBech32FromHash(votingProcedure.voter.credential.hash)
: votingProcedure.voter.credential.hash.toString();
return {
voter: {
type: voterType,
type: t(`core.votingProcedures.voterType.${voterType}`),
dRepId: drepId
},
votes: votingProcedure.votes.map((vote) => ({
Expand All @@ -71,7 +83,7 @@ export const VotingProceduresContainer = ({ signTxData, errorMessage }: Props):
...(explorerBaseUrl && { txHashUrl: `${explorerBaseUrl}/${vote.actionId.id}` })
},
votingProcedure: {
vote: getVote(vote.votingProcedure.vote),
vote: t(`core.votingProcedures.votes.${getVote(vote.votingProcedure.vote)}`),
anchor: !!vote.votingProcedure.anchor?.url && {
url: vote.votingProcedure.anchor?.url,
hash: vote.votingProcedure.anchor?.dataHash.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mockPreprodCexplorerBaseUrl = 'PREPROD_CEXPLORER_BASE_URL';
const mockCexplorerUrlPathsTx = 'CEXPLORER_URL_PATHS.TX';
import * as React from 'react';
import { cleanup, render } from '@testing-library/react';
import { VotingProceduresContainer, getVote, getVoterType } from '../VotingProceduresContainer';
import { VoterType, Votes, VotingProceduresContainer, getVote, getVoterType } from '../VotingProceduresContainer';
import '@testing-library/jest-dom';
import { I18nextProvider } from 'react-i18next';
import { StoreProvider } from '@src/stores';
Expand Down Expand Up @@ -203,15 +203,15 @@ describe('Testing VotingProceduresContainer component', () => {
expect(queryByTestId('VotingProcedures')).toBeInTheDocument();
// eslint-disable-next-line unicorn/consistent-function-scoping
const getExpectedDrepId = (type: string) => (hash: Wallet.Crypto.Hash28ByteBase16) =>
type === 'DRep'
type === VoterType.DREP
? Wallet.Cardano.DRepID(Wallet.HexBlob.toTypedBech32('drep', Wallet.HexBlob(hash)))
: hash.toString();
expect(mockVotingProcedures).toHaveBeenLastCalledWith(
{
dappInfo,
data: voters.map(({ __typename }, index) => ({
voter: {
type: getVoterType(__typename),
type: t(`core.votingProcedures.voterType.${getVoterType(__typename)}`),
dRepId: getExpectedDrepId(getVoterType(__typename))(voters[index].credential.hash)
},
votes: votingProcedures[index].votes.map((vote) => ({
Expand All @@ -221,7 +221,7 @@ describe('Testing VotingProceduresContainer component', () => {
txHashUrl: `${mockPreprodCexplorerBaseUrl}/${mockCexplorerUrlPathsTx}/${vote.actionId.id}`
},
votingProcedure: {
vote: getVote(vote.votingProcedure.vote),
vote: t(`core.votingProcedures.votes.${getVote(vote.votingProcedure.vote)}`),
anchor: !!vote.votingProcedure.anchor?.url && {
url: vote.votingProcedure.anchor?.url,
hash: vote.votingProcedure.anchor?.dataHash.toString()
Expand Down Expand Up @@ -279,16 +279,16 @@ describe('Testing VotingProceduresContainer component', () => {
});

test('testing getVoterType', () => {
expect(getVoterType(constitutionalCommitteeKeyHashVoter.__typename)).toEqual('Constitutional Committee');
expect(getVoterType(constitutionalCommitteeScriptHashVoter.__typename)).toEqual('Constitutional Committee');
expect(getVoterType(drepKeyHashVoter.__typename)).toEqual('DRep');
expect(getVoterType(drepScriptHashVoter.__typename)).toEqual('DRep');
expect(getVoterType(stakePoolKeyHashVoter.__typename)).toEqual('SPO');
expect(getVoterType(constitutionalCommitteeKeyHashVoter.__typename)).toEqual(VoterType.CONSTITUTIONAL_COMMITTEE);
expect(getVoterType(constitutionalCommitteeScriptHashVoter.__typename)).toEqual(VoterType.CONSTITUTIONAL_COMMITTEE);
expect(getVoterType(drepKeyHashVoter.__typename)).toEqual(VoterType.DREP);
expect(getVoterType(drepScriptHashVoter.__typename)).toEqual(VoterType.DREP);
expect(getVoterType(stakePoolKeyHashVoter.__typename)).toEqual(VoterType.SPO);
});

test('testing getVote', () => {
expect(getVote(Wallet.Cardano.Vote.yes)).toEqual('Yes');
expect(getVote(Wallet.Cardano.Vote.no)).toEqual('No');
expect(getVote(Wallet.Cardano.Vote.abstain)).toEqual('Abstain');
expect(getVote(Wallet.Cardano.Vote.yes)).toEqual(Votes.YES);
expect(getVote(Wallet.Cardano.Vote.no)).toEqual(Votes.NO);
expect(getVote(Wallet.Cardano.Vote.abstain)).toEqual(Votes.ABSTAIN);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,22 @@ export const useTxSummary = ({
if (txType === TxType.Send) {
return walletInfo.addresses.every((addr) => output.address !== addr.address);
}
return true;
// Don't show withdrawl tx's etc
return output.address.toString() !== walletInfo.addresses[0].address.toString();
});

// eslint-disable-next-line unicorn/no-array-reduce
const txSummaryOutputs: Wallet.Cip30SignTxSummary['outputs'] = externalOutputs.reduce((acc, txOut) => {
// Don't show withdrawl tx's etc
if (txOut.address.toString() === walletInfo.addresses[0].address.toString()) return acc;

return [
const txSummaryOutputs: Wallet.Cip30SignTxSummary['outputs'] = externalOutputs.reduce(
(acc, txOut) => [
...acc,
{
coins: Wallet.util.lovelacesToAdaString(txOut.value.coins.toString()),
recipient: addressToNameMap?.get(txOut.address.toString()) || txOut.address.toString(),
...(txOut.value.assets?.size > 0 && { assets: createAssetList(txOut.value.assets) })
}
];
}, []);
],
[]
);

return {
fee: Wallet.util.lovelacesToAdaString(tx.body.fee.toString()),
Expand Down
12 changes: 11 additions & 1 deletion apps/browser-extension-wallet/src/lib/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,17 @@
"hash": "Anchor Hash",
"url": "Anchor URL"
},
"dRepId": "DRep ID"
"dRepId": "DRep ID",
"voterTypes": {
"constitutionalCommittee": "Constitutional Committee",
"spo": "SPO",
"drep": "DRep"
},
"votes": {
"yes": "Yes",
"no": "No",
"abstain": "Abstain"
}
},
"drepRegistration": {
"title": "Confirm DRep Registration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export const TransactionDetails = ({
</div>
<div
data-testid="tx-hash-detail"
className={cn(styles.detail, !!openExternalLink && styles.hash, {
className={cn(styles.detail, {
[styles.hash]: openExternalLink,
[styles.txLink]: isSuccess && !!openExternalLink
})}
onClick={openExternalLink}
Expand Down