Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into e2e-test-parallel-runs
Browse files Browse the repository at this point in the history
  • Loading branch information
oldGreg5 committed May 7, 2024
2 parents 8bfc4ab + 8b4f652 commit 7e16d88
Show file tree
Hide file tree
Showing 73 changed files with 1,386 additions and 1,192 deletions.
6 changes: 3 additions & 3 deletions apps/browser-extension-wallet/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ CEXPLORER_URL_PREPROD=https://preprod.cexplorer.io
CEXPLORER_URL_SANCHONET=https://sancho.cexplorer.io

# ADA Handle URLs
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
ADA_HANDLE_URL_MAINNET=https://dev-mainnet.lw.iog.io/
ADA_HANDLE_URL_PREPROD=https://dev-preprod.lw.iog.io/
ADA_HANDLE_URL_PREVIEW=https://dev-preview.lw.iog.io/
ADA_HANDLE_URL_SANCHONET=

# Manifest.json
Expand Down
8 changes: 4 additions & 4 deletions apps/browser-extension-wallet/.env.developerpreview
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SAVED_PRICE_DURATION_IN_MINUTES=720
# Feature Flags
USE_PASSWORD_VERIFICATION=false
USE_DAPP_CONNECTOR=true
USE_TREZOR_HW=true
USE_TREZOR_HW=false
USE_TOKEN_PRICING=true
USE_NFT_FOLDERS=true
USE_MULTI_CURRENCY=true
Expand Down Expand Up @@ -74,9 +74,9 @@ CEXPLORER_URL_PREPROD=https://preprod.cexplorer.io
CEXPLORER_URL_SANCHONET=https://sancho.cexplorer.io

# ADA Handle URLs
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
ADA_HANDLE_URL_MAINNET=https://dev-mainnet.lw.iog.io
ADA_HANDLE_URL_PREVIEW=https://dev-preview.lw.iog.io
ADA_HANDLE_URL_PREPROD=https://dev-preprod.lw.iog.io
ADA_HANDLE_URL_SANCHONET=

# Manifest.json
Expand Down
6 changes: 3 additions & 3 deletions apps/browser-extension-wallet/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ CEXPLORER_URL_PREPROD=https://preprod.cexplorer.io
CEXPLORER_URL_SANCHONET=https://sancho.cexplorer.io

# ADA Handle URLs
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
ADA_HANDLE_URL_MAINNET=https://dev-mainnet.lw.iog.io
ADA_HANDLE_URL_PREVIEW=https://dev-preview.lw.iog.io
ADA_HANDLE_URL_PREPROD=https://dev-preprod.lw.iog.io
ADA_HANDLE_URL_SANCHONET=

# Manifest.json
Expand Down
1 change: 0 additions & 1 deletion apps/browser-extension-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@cardano-sdk/wallet": "0.37.3",
"@cardano-sdk/web-extension": "0.27.3",
"@emurgo/cip14-js": "~3.0.1",
"@koralabs/handles-public-api-interfaces": "^1.6.6",
"@lace/cardano": "0.1.0",
"@lace/common": "0.1.0",
"@lace/core": "0.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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<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'
[Cardano.NetworkMagics.Mainnet]: process.env.ADA_HANDLE_URL_MAINNET,
[Cardano.NetworkMagics.Preprod]: process.env.ADA_HANDLE_URL_PREPROD,
[Cardano.NetworkMagics.Preview]: process.env.ADA_HANDLE_URL_PREVIEW
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export const SignTransaction = (): React.ReactElement => {
return !password;
}, [request, password]);

const onCancel = () => {
analytics.sendEventToPostHog(PostHogAction.SendTransactionConfirmationCancelClick, {
[TX_CREATION_TYPE_KEY]: TxCreationType.External
});
setPreviousView();
};

return (
<Layout title={undefined}>
<div className={styles.passwordContainer}>
Expand All @@ -82,12 +89,7 @@ export const SignTransaction = (): React.ReactElement => {
>
{t('dapp.confirm.btn.confirm')}
</Button>
<Button
onClick={setPreviousView}
color="secondary"
className={styles.actionBtn}
data-testid="sign-transaction-cancel"
>
<Button onClick={onCancel} color="secondary" className={styles.actionBtn} data-testid="sign-transaction-cancel">
{t('dapp.confirm.btn.cancel')}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ConfirmTransaction = (): React.ReactElement => {
fetchTxType();
}, [req]);

const onConfirm = () => {
const onConfirmTransaction = () => {
analytics.sendEventToPostHog(PostHogAction.SendTransactionSummaryConfirmClick, {
[TX_CREATION_TYPE_KEY]: TxCreationType.External
});
Expand Down Expand Up @@ -85,6 +85,13 @@ export const ConfirmTransaction = (): React.ReactElement => {
};
}, [setSignTxRequest, setDappInfo]);

const onCancelTransaction = () => {
analytics.sendEventToPostHog(PostHogAction.SendTransactionSummaryCancelClick, {
[TX_CREATION_TYPE_KEY]: TxCreationType.External
});
disallowSignTx(true);
};

useOnBeforeUnload(disallowSignTx);

return (
Expand All @@ -97,7 +104,7 @@ export const ConfirmTransaction = (): React.ReactElement => {
{!confirmTransactionError && (
<div className={styles.actions}>
<Button
onClick={onConfirm}
onClick={onConfirmTransaction}
loading={isHardwareWallet && isConfirmingTx}
data-testid="dapp-transaction-confirm"
className={styles.actionBtn}
Expand All @@ -109,7 +116,7 @@ export const ConfirmTransaction = (): React.ReactElement => {
<Button
color="secondary"
data-testid="dapp-transaction-cancel"
onClick={() => disallowSignTx(true)}
onClick={onCancelTransaction}
className={styles.actionBtn}
>
{t('dapp.confirm.btn.cancel')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { VotingProcedures } from '@lace/core';
import { getDRepId, hasValidDrepRegistration, votingProceduresInspector } from './utils';
import { getDRepId, votingProceduresInspector } from './utils';
import { useCexplorerBaseUrl, useDisallowSignTx } from './hooks';
import { getVote, getVoterType } from '@src/utils/tx-inspection';
import { Wallet } from '@lace/cardano';

import { NonRegisteredUserModal } from './NonRegisteredUserModal/NonRegisteredUserModal';
import { useViewsFlowContext } from '@providers';
import { useWalletStore } from '@src/stores';
Expand All @@ -15,7 +16,7 @@ export const VotingProceduresContainer = (): React.ReactElement => {
signTxRequest: { request },
dappInfo
} = useViewsFlowContext();
const { walletState } = useWalletStore();
const { inMemoryWallet } = useWalletStore();
const [votingProcedures, setVotingProcedures] = useState<Wallet.Cardano.VotingProcedures>([]);
const [isNonRegisteredUserModalVisible, setIsNonRegisteredUserModalVisible] = useState<boolean>(false);
const [userAckNonRegisteredState, setUserAckNonRegisteredState] = useState<boolean>(false);
Expand All @@ -31,9 +32,15 @@ export const VotingProceduresContainer = (): React.ReactElement => {
}, [request]);

useEffect(() => {
if (!walletState?.transactions.history || userAckNonRegisteredState) return;
setIsNonRegisteredUserModalVisible(!hasValidDrepRegistration(walletState.transactions.history));
}, [walletState?.transactions.history, userAckNonRegisteredState]);
if (userAckNonRegisteredState) return () => void 0;
const subscription = inMemoryWallet?.governance?.isRegisteredAsDRep$?.subscribe(
(hasValidDrepRegistration): void => {
setIsNonRegisteredUserModalVisible(!hasValidDrepRegistration);
}
);

return () => subscription?.unsubscribe();
}, [inMemoryWallet?.governance?.isRegisteredAsDRep$, userAckNonRegisteredState]);

const explorerBaseUrl = useCexplorerBaseUrl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const mockUseTranslation = jest.fn(() => ({ t }));
const mockVotingProcedures = jest.fn();
const mockNonRegisteredUserModal = jest.fn();
const mockUseDisallowSignTx = jest.fn();
const mockHasValidDrepRegistration = jest.fn();
const mockPreprodCexplorerBaseUrl = 'PREPROD_CEXPLORER_BASE_URL';
const mockCexplorerUrlPathsTx = 'CEXPLORER_URL_PATHS.TX';
import * as React from 'react';
Expand All @@ -23,6 +22,7 @@ import { getWrapper } from '../testing.utils';
import { getVoterType, getVote, VoterTypeEnum, VotesEnum } from '@src/utils/tx-inspection';
import { drepIDasBech32FromHash } from '../utils';
import { TransactionWitnessRequest } from '@cardano-sdk/web-extension';
import { of } from 'rxjs';

jest.mock('@src/stores', () => ({
...jest.requireActual<any>('@src/stores'),
Expand Down Expand Up @@ -68,11 +68,6 @@ jest.mock('react-i18next', () => {
};
});

jest.mock('../utils', () => ({
...jest.requireActual<any>('../utils'),
hasValidDrepRegistration: mockHasValidDrepRegistration
}));

jest.mock('../hooks', () => {
const original = jest.requireActual('../hooks');
return {
Expand Down Expand Up @@ -179,11 +174,12 @@ jest.mock('@providers', () => ({

describe('Testing VotingProceduresContainer component', () => {
beforeEach(() => {
mockHasValidDrepRegistration.mockReset();
mockHasValidDrepRegistration.mockReturnValue(true);
mockUseWalletStore.mockReset();
mockUseWalletStore.mockImplementation(() => ({
environmentName: 'Preprod'
environmentName: 'Preprod',
inMemoryWallet: {
governance: {}
}
}));
mockVotingProcedures.mockReset();
mockVotingProcedures.mockReturnValue(<span data-testid="VotingProcedures" />);
Expand Down Expand Up @@ -254,14 +250,12 @@ describe('Testing VotingProceduresContainer component', () => {
});

test('should handle NonRegisteredUserModal onConfirm', async () => {
mockHasValidDrepRegistration.mockReset();
mockHasValidDrepRegistration.mockReturnValue(false);
mockUseWalletStore.mockReset();
mockUseWalletStore.mockImplementation(() => ({
environmentName: 'Preprod',
walletState: {
transactions: {
history: []
inMemoryWallet: {
governance: {
isRegisteredAsDRep$: of(false)
}
}
}));
Expand Down Expand Up @@ -291,14 +285,12 @@ describe('Testing VotingProceduresContainer component', () => {
const disallowSignTxMock = jest.fn();
mockUseDisallowSignTx.mockReset();
mockUseDisallowSignTx.mockReturnValue(disallowSignTxMock);
mockHasValidDrepRegistration.mockReset();
mockHasValidDrepRegistration.mockReturnValue(false);
mockUseWalletStore.mockReset();
mockUseWalletStore.mockImplementation(() => ({
environmentName: 'Preprod',
walletState: {
transactions: {
history: []
inMemoryWallet: {
governance: {
isRegisteredAsDRep$: of(false)
}
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
getTxType,
drepIDasBech32FromHash,
pubDRepKeyToHash,
depositPaidWithSymbol,
hasValidDrepRegistration
depositPaidWithSymbol
} from '../utils';

jest.mock('@cardano-sdk/core', () => ({
Expand Down Expand Up @@ -171,59 +170,4 @@ describe('Testing utils', () => {
'coinId Unknown not supported'
);
});

describe('hasValidDrepRegistration', () => {
test('should return false if there transactions', () => {
const transactions = [] as unknown as Wallet.Cardano.HydratedTx[];
expect(hasValidDrepRegistration(transactions)).toBe(false);
});

test('should return false if there is no certificates', () => {
const transactions = [{ body: {} }, { body: { certificates: [] } }] as unknown as Wallet.Cardano.HydratedTx[];
expect(hasValidDrepRegistration(transactions)).toBe(false);
});

test('should return true if first certificate has RegisterDelegateRepresentative __typename', () => {
const transactions = [
{
body: {
certificates: [
{ __typename: Wallet.Cardano.CertificateType.RegisterDelegateRepresentative },
{ __typename: Wallet.Cardano.CertificateType.UnregisterDelegateRepresentative }
]
}
},
{
body: {
certificates: [
{ __typename: Wallet.Cardano.CertificateType.UnregisterDelegateRepresentative },
{ __typename: Wallet.Cardano.CertificateType.RegisterDelegateRepresentative }
]
}
}
] as unknown as Wallet.Cardano.HydratedTx[];
expect(hasValidDrepRegistration(transactions)).toBe(true);
});
test('should return false if first certificate has UnregisterDelegateRepresentative __typename', () => {
const transactions = [
{
body: {
certificates: [
{ __typename: Wallet.Cardano.CertificateType.UnregisterDelegateRepresentative },
{ __typename: Wallet.Cardano.CertificateType.RegisterDelegateRepresentative }
]
}
},
{
body: {
certificates: [
{ __typename: Wallet.Cardano.CertificateType.RegisterDelegateRepresentative },
{ __typename: Wallet.Cardano.CertificateType.UnregisterDelegateRepresentative }
]
}
}
] as unknown as Wallet.Cardano.HydratedTx[];
expect(hasValidDrepRegistration(transactions)).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ export const depositPaidWithSymbol = (deposit: bigint, coinId: Wallet.CoinId): s
}
};

export const hasValidDrepRegistration = (history: Wallet.Cardano.HydratedTx[]): boolean => {
for (const transaction of history) {
const drepRegistrationOrRetirementCerticicate = transaction.body.certificates?.find((cert) =>
[CertificateType.UnregisterDelegateRepresentative, CertificateType.RegisterDelegateRepresentative].includes(
cert.__typename
)
);

if (drepRegistrationOrRetirementCerticicate) {
return drepRegistrationOrRetirementCerticicate.__typename === CertificateType.RegisterDelegateRepresentative;
}
}
return false;
};

export const getDRepId = (voter: Wallet.Cardano.Voter): Wallet.Cardano.DRepID | string =>
getVoterType(voter.__typename) === VoterTypeEnum.DREP
? drepIDasBech32FromHash(voter.credential.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import { NftDetail as NftDetailView } from '@lace/core';
import { Wallet } from '@lace/cardano';
import { useTranslation } from 'react-i18next';
import { SendFlowTriggerPoints, useOutputInitialState } from '@src/views/browser-view/features/send-transaction';
import { DEFAULT_WALLET_BALANCE, SEND_NFT_DEFAULT_AMOUNT } from '@src/utils/constants';
import { APP_MODE_POPUP, DEFAULT_WALLET_BALANCE, SEND_NFT_DEFAULT_AMOUNT } from '@src/utils/constants';
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';
import { useAnalyticsContext } from '@providers';
import { buttonIds } from '@hooks/useEnterKeyPress';
import { withNftsFoldersContext } from '../context';

export const NftDetail = (): React.ReactElement => {
const { inMemoryWallet } = useWalletStore();
export const NftDetail = withNftsFoldersContext((): React.ReactElement => {
const {
inMemoryWallet,
walletUI: { appMode }
} = useWalletStore();
const { t } = useTranslation();
const analytics = useAnalyticsContext();

Expand All @@ -33,12 +37,6 @@ export const NftDetail = (): React.ReactElement => {

const amount = useMemo(() => Wallet.util.calculateAssetBalance(bigintBalance, assetInfo), [assetInfo, bigintBalance]);

const nftDetailTranslation = {
tokenInformation: t('core.nftDetail.tokenInformation'),
attributes: t('core.nftDetail.attributes'),
setAsAvatar: t('core.nftDetail.setAsAvatar')
};

const handleOpenSend = () => {
// eslint-disable-next-line camelcase
analytics.sendEventToPostHog(PostHogAction.SendClick, { trigger_point: SendFlowTriggerPoints.NFTS });
Expand All @@ -64,11 +62,11 @@ export const NftDetail = (): React.ReactElement => {
{assetInfo && (
<NftDetailView
{...nftDetailSelector(assetInfo)}
isPopup={appMode === APP_MODE_POPUP}
amount={amount}
translations={nftDetailTranslation}
title={<h2 className={styles.secondaryTitle}>{assetInfo.nftMetadata?.name ?? assetInfo.fingerprint}</h2>}
/>
)}
</Drawer>
);
};
});

0 comments on commit 7e16d88

Please sign in to comment.