Skip to content
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

fix: fix issues with incorrect data in HRD #1051

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
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { DeployIcon, getBlockExplorerContractUrl } from '@src/constants';
import { DeployIcon, getBlockExplorerContractPackageUrl } from '@src/constants';

import { SimpleContainer } from '@popup/pages/deploy-details/components/common';

Expand Down Expand Up @@ -32,7 +32,7 @@ export const AssociatedActionRows = ({

const { casperLiveUrl } = useSelector(selectApiConfigBasedOnActiveNetwork);

const link = getBlockExplorerContractUrl(
const link = getBlockExplorerContractPackageUrl(
casperLiveUrl,
contractPackageHash || ''
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const CsprMarketActionRows = ({ deploy }: CsprMarketActionRowsProps) => {
<SimpleContainer title={title}>
<NftInfoRow
nftTokenIds={nftTokenIds}
publicKey={deploy.collectionHash}
publicKey={deploy.collectionHash || deploy.contractPackageHash}
/>
<ContractInfoRow
publicKey={contractPackageHash}
Expand All @@ -56,17 +56,19 @@ export const CsprMarketActionRows = ({ deploy }: CsprMarketActionRowsProps) => {
if (isOfferAction) {
return (
<SimpleContainer title={title}>
<AmountRow
label="of"
amount={deploy.formattedDecimalAmount}
symbol="CSPR"
fiatAmount={deploy.fiatAmount}
/>
{Number(deploy.formattedDecimalAmount) ? (
<AmountRow
label="of"
amount={deploy.formattedDecimalAmount}
symbol="CSPR"
fiatAmount={deploy.fiatAmount}
/>
) : null}
<NftInfoRow
nftTokenIds={nftTokenIds}
imgLogo={offererAccountInfo?.brandingLogo}
contractName={offererAccountInfo?.name}
publicKey={deploy.contractPackageHash}
publicKey={deploy.collectionHash || deploy.contractPackageHash}
label="for"
/>
<AccountInfoRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { DeployIcon, getBlockExplorerContractUrl } from '@src/constants';
import { DeployIcon, getBlockExplorerContractPackageUrl } from '@src/constants';

import { SimpleContainer } from '@popup/pages/deploy-details/components/common';

Expand Down Expand Up @@ -32,7 +32,7 @@ export const DefaultActionRows = ({

const { casperLiveUrl } = useSelector(selectApiConfigBasedOnActiveNetwork);

const link = getBlockExplorerContractUrl(
const link = getBlockExplorerContractPackageUrl(
casperLiveUrl,
contractPackageHash || ''
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DeployIcon, NftDeployEntryPoint } from '@src/constants';

import { DefaultActionRows } from '@popup/pages/deploy-details/components/action-rows/default-action-rows';
import {
ContractInfoRow,
NftInfoRow,
SimpleContainer
} from '@popup/pages/deploy-details/components/common';
Expand Down Expand Up @@ -135,11 +134,7 @@ export const NftActionsRows = ({ deploy }: NftActionsRowsProps) => {
label="for"
isApprove
/>
<ContractInfoRow
contractName={contractName}
publicKey={recipientKey}
label="to"
/>
<AccountInfoRow publicKey={recipientKey} label="to" isAction />
</SimpleContainer>
);
}
Expand Down
14 changes: 10 additions & 4 deletions src/apps/popup/pages/deploy-details/components/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useSelector } from 'react-redux';
import styled from 'styled-components';

import { getBlockExplorerContractUrl, getContractNftUrl } from '@src/constants';
import { getBlockExplorerContractPackageUrl } from '@src/constants';
import { isEqualCaseInsensitive } from '@src/utils';

import { selectApiConfigBasedOnActiveNetwork } from '@background/redux/settings/selectors';
Expand Down Expand Up @@ -85,7 +85,7 @@
}: ActionContainerWithLinkProps) => {
const { casperLiveUrl } = useSelector(selectApiConfigBasedOnActiveNetwork);

const link = getBlockExplorerContractUrl(
const link = getBlockExplorerContractPackageUrl(
casperLiveUrl,
contractPackageHash || ''
);
Expand Down Expand Up @@ -129,7 +129,10 @@
selectApiConfigBasedOnActiveNetwork
);

const link = getBlockExplorerContractUrl(casperLiveUrl, publicKey || '');
const link = getBlockExplorerContractPackageUrl(
casperLiveUrl,
publicKey || ''
);

const getCollectionName = useCallback(() => {
if (
Expand Down Expand Up @@ -172,7 +175,7 @@
<Link
color="contentAction"
target="_blank"
href={getContractNftUrl(casperLiveUrl, publicKey || '', id)}

Check failure on line 178 in src/apps/popup/pages/deploy-details/components/common.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Cannot find name 'getContractNftUrl'.
>
<Typography type="captionRegular" color="contentAction" ellipsis>
{id}
Expand Down Expand Up @@ -240,7 +243,10 @@

const { casperLiveUrl } = useSelector(selectApiConfigBasedOnActiveNetwork); // Fetch the live Casper network URL from Redux store. // Assuming 'publicKey' is the public key of the contract. // Replace 'casperLiveUrl' with the actual live Casper network URL. // Fetch the contract details using the public key. // Display the contract name, icon, and additional information. // If the contract details are not found, display a

const link = getBlockExplorerContractUrl(casperLiveUrl, publicKey || '');
const link = getBlockExplorerContractPackageUrl(
casperLiveUrl,
publicKey || ''
);

return (
<AlignedFlexRow gap={SpacingSize.Small}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ export const DeployDetailsResult = ({ deploy }: DeployDetailsResultProps) => {
return null;
}

const showResultRow = Boolean(
deploy.status !== 'error' &&
(deploy.transfersActionsResult.length ||
(isNftDeploy(deploy) && deploy.nftActionsResult.length) ||
(isCep18Deploy(deploy) && deploy.cep18ActionsResult.length) ||
isAssociatedKeysDeploy(deploy))
);

if (!showResultRow) return null;

if (isAssociatedKeysDeploy(deploy)) {
return (
<Container>
Expand All @@ -87,40 +97,23 @@ export const DeployDetailsResult = ({ deploy }: DeployDetailsResultProps) => {
fiatAmount={action.fiatAmount}
/>
))}
{isCep18Deploy(deploy) &&
deploy.cep18ActionsResult.map((action, id) => (
<Cep18ResultRows
action={action}
key={id}
contractPackageHash={deploy.contractPackageHash}
/>
))}
{(isNftDeploy(deploy) || isCasperMarketDeploy(deploy)) &&
deploy.nftActionsResult.map((action, id) => (
<NftResultRows
action={action}
key={id}
contractPackageHash={deploy.contractPackageHash}
/>
))}
</Container>
);
}

if (
(isNftDeploy(deploy) || isCasperMarketDeploy(deploy)) &&
deploy.nftActionsResult.length
) {
return (
<Container>
{deploy.nftActionsResult.map((action, id) => (
<NftResultRows
action={action}
key={id}
contractPackageHash={deploy.contractPackageHash}
/>
))}
</Container>
);
}

if (isCep18Deploy(deploy) && deploy.cep18ActionsResult.length) {
return (
<Container>
{deploy.cep18ActionsResult.map((action, id) => (
<Cep18ResultRows
action={action}
key={id}
contractPackageHash={deploy.contractPackageHash}
/>
))}
</Container>
);
}

return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@src/constants';

import {
ContractInfoRow,
NftInfoRow,
SimpleContainer
} from '@popup/pages/deploy-details/components/common';
Expand Down Expand Up @@ -56,8 +55,8 @@ export const NftResultRows = ({
defaultSvg={DeployIcon.NFTDefault}
/>
<AccountInfoRow
publicKey={recipientKey}
accountName={recipientAccountInfo?.name}
publicKey={recipientKey || callerPublicKey}
accountName={recipientAccountInfo?.name || callerAccountInfo?.name}
label="owned by"
isAction
iconSize={20}
Expand Down Expand Up @@ -142,11 +141,7 @@ export const NftResultRows = ({
label={'for'}
isApprove
/>
<ContractInfoRow
publicKey={recipientKey}
contractName={contractName}
label="to"
/>
<AccountInfoRow publicKey={recipientKey} label="to" isAction />
</SimpleContainer>
);
}
Expand Down
16 changes: 12 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ export const MAX_DELEGATORS = 1200;

export const PENDING_DEPLOY_REFETCH_INTERVAL = 5 * 1000;

export const getBlockExplorerAccountUrl = (baseUrl: string, hash: string) =>
`${baseUrl}/account/${hash}`;
export const getBlockExplorerAccountUrl = (
casperLiveUrl: string,
publicKey: string
) => {
const path = publicKey?.includes('uref') ? 'uref' : 'account';

return `${casperLiveUrl}/${path}/${publicKey}`;
};

export const getBlockExplorerContractUrl = (baseUrl: string, hash: string) =>
`${baseUrl}/contract-package/${hash}`;
export const getBlockExplorerContractPackageUrl = (
casperLiveUrl: string,
contractPackageHash: string
) => `${casperLiveUrl}/contract-package/${contractPackageHash}`;

export const getBlockExplorerDeployUrl = (
casperLiveUrl: string,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/layout/header/header-view-in-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSelector } from 'react-redux';

import {
getBlockExplorerAccountUrl,
getBlockExplorerContractUrl,
getBlockExplorerContractPackageUrl,
getBlockExplorerDeployUrl,
getContractNftUrl
} from '@src/constants';
Expand Down Expand Up @@ -69,7 +69,7 @@ export function HeaderViewInExplorer({

if (token) {
setHrefToTokenOnCasperLive(
getBlockExplorerContractUrl(
getBlockExplorerContractPackageUrl(
casperLiveUrl,
token.contract_package_hash
)
Expand Down
31 changes: 27 additions & 4 deletions src/libs/ui/components/account-info-row/account-info-row.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Maybe } from 'casper-wallet-core/src/typings/common';
import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import styled from 'styled-components';

import { getBlockExplorerAccountUrl } from '@src/constants';
import {
getBlockExplorerAccountUrl,
getBlockExplorerContractPackageUrl
} from '@src/constants';
import { isEqualCaseInsensitive } from '@src/utils';

import { selectAllContacts } from '@background/redux/contacts/selectors';
Expand Down Expand Up @@ -44,6 +47,8 @@ export const AccountInfoRow = ({
iconSize = 16,
isAction = false
}: AccountInfoRowProps) => {
const [linkUrl, setLinkUrl] = useState('');

const { t } = useTranslation();

const accounts = useSelector(selectVaultAccounts);
Expand All @@ -55,7 +60,25 @@ export const AccountInfoRow = ({
csprMarketContractHash
} = useSelector(selectApiConfigBasedOnActiveNetwork);

const link = getBlockExplorerAccountUrl(casperLiveUrl, publicKey || '');
useEffect(() => {
if (
publicKey &&
(isEqualCaseInsensitive(publicKey, csprStudioCep47ContractHash) ||
isEqualCaseInsensitive(publicKey, csprMarketContractHash))
) {
setLinkUrl(
getBlockExplorerContractPackageUrl(casperLiveUrl, publicKey || '')
);
} else {
setLinkUrl(getBlockExplorerAccountUrl(casperLiveUrl, publicKey || ''));
}
}, [
auctionPoolContractHash,
casperLiveUrl,
csprMarketContractHash,
csprStudioCep47ContractHash,
publicKey
]);

const accountLabel = useMemo(
() => accounts.find(acc => acc.publicKey === publicKey)?.name,
Expand Down Expand Up @@ -101,7 +124,7 @@ export const AccountInfoRow = ({
<>
<Link
color="inherit"
href={isAction ? link : undefined}
href={isAction ? linkUrl : undefined}
target="_blank"
>
<AccountInfoNameContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export const NativeTransferDeployRows = ({
<AccountInfoRow
label={deploy.isReceive ? 'from' : 'to'}
publicKey={
deploy.isReceive ? deploy.callerPublicKey : deploy.recipientKey
deploy.isReceive
? deploy.callerPublicKey ||
deploy.callerAccountInfo?.accountHash ||
''
: deploy.recipientKey ||
deploy.recipientAccountInfo?.accountHash ||
''
}
accountName={
deploy.isReceive
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ui/components/deploy-plate/deploy-plate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const DeployPlate = ({
</Container>
);
}
//

if (isCep18Deploy(deploy)) {
return (
<Container
Expand Down
Loading