From 1e601eda5a1363719a76a65acfe369625e1c99d8 Mon Sep 17 00:00:00 2001 From: Sorin Chis Date: Thu, 27 Feb 2025 13:01:51 +0200 Subject: [PATCH 1/2] update network config --- .../app/UI/utils/createCurrentWalletInfo.ts | 23 +---- .../app/UI/utils/network-config.ts | 95 +++++++++++++++++++ 2 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 packages/yoroi-extension/app/UI/utils/network-config.ts diff --git a/packages/yoroi-extension/app/UI/utils/createCurrentWalletInfo.ts b/packages/yoroi-extension/app/UI/utils/createCurrentWalletInfo.ts index 707415e9b8..5752b5e34c 100644 --- a/packages/yoroi-extension/app/UI/utils/createCurrentWalletInfo.ts +++ b/packages/yoroi-extension/app/UI/utils/createCurrentWalletInfo.ts @@ -6,25 +6,7 @@ import { genLookupOrFail, getTokenIdentifierIfExists, getTokenStrictName } from import { splitAmount, truncateToken } from '../../utils/formatters.js'; import { cardanoAdaBase64Logo } from '../features/portfolio/common/helpers/constants'; import { CurrentWalletType } from '../types/currrentWallet'; - -// TODO To be added and constructed from wallet apo -const primaryTokenFullInfo = { - application: 'coin', - decimals: 6, - description: 'Cardano', - fingerprint: '', - id: '.', - name: 'ADA', - nature: 'primary', - originalImage: '', - reference: '', - status: 'valid', - symbol: '₳', - tag: '', - ticker: 'ADA', - type: 'ft', - website: 'https://www.cardano.org/', -}; +import { networkConfigs } from './network-config'; export const mapStakingKeyStateToGovernanceAction = (state: any) => { if (!state.drepDelegation) return null; @@ -183,6 +165,7 @@ export const createCurrrentWalletInfo = (stores: any): CurrentWalletType | undef const selectedExplorer = explorers.selectedExplorer.get(networkId); const explorerTransactionInfo = selectedExplorer.getOrDefault('token'); + const primaryTokenInfo = networkConfigs[networkId].primaryTokenInfo; return { currentPool: walletCurrentPoolInfo, @@ -197,7 +180,7 @@ export const createCurrrentWalletInfo = (stores: any): CurrentWalletType | undef backendService: BackendService, backendServiceZero: BackendServiceZero, isHardwareWallet: isHardware, - primaryTokenInfo: { ...primaryTokenFullInfo, quantity: shiftedAmount }, + primaryTokenInfo: { ...primaryTokenInfo, quantity: shiftedAmount }, stakingAddress: selectedWallet.stakingAddress, walletBalance: { ada: `${beforeDecimalRewards}${afterDecimalRewards}`, diff --git a/packages/yoroi-extension/app/UI/utils/network-config.ts b/packages/yoroi-extension/app/UI/utils/network-config.ts new file mode 100644 index 0000000000..6621d16d08 --- /dev/null +++ b/packages/yoroi-extension/app/UI/utils/network-config.ts @@ -0,0 +1,95 @@ +import { createPrimaryTokenInfo } from '@yoroi/portfolio'; +import { Chain, Network } from '@yoroi/types'; +import { freeze } from 'immer'; + +export const primaryTokenInfoMainnet = createPrimaryTokenInfo({ + decimals: 6, + name: 'ADA', + ticker: 'ADA', + symbol: '₳', + reference: '', + tag: '', + website: 'https://www.cardano.org/', + originalImage: '', + description: 'Cardano', +}); + +const primaryTokenInfoAnyTestnet = createPrimaryTokenInfo({ + decimals: 6, + name: 'TADA', + ticker: 'TADA', + symbol: '₳', + reference: '', + tag: '', + website: 'https://www.cardano.org/', + originalImage: '', + description: 'Cardano', +}); + +export const shelleyEraConfig: Readonly = freeze( + { + name: 'shelley', + start: new Date('2020-07-29T21:44:51.000Z'), + end: undefined, + slotInSeconds: 1, + slotsPerEpoch: 432000, + }, + true +); + +export const byronEraConfig: Readonly = freeze( + { + name: 'byron', + start: new Date('2017-09-23T21:44:51.000Z'), + end: new Date('2020-07-29T21:44:51.000Z'), + slotInSeconds: 20, + slotsPerEpoch: 21600, + }, + true +); + +export const shelleyPreprodEraConfig: Readonly = freeze( + { + name: 'shelley', + start: new Date('2022-06-01T01:00:00.000Z'), + end: undefined, + slotInSeconds: 1, + slotsPerEpoch: 432000, + }, + true +); + +export const networkConfigs = { + 0: { + network: Chain.Network.Mainnet, + primaryTokenInfo: primaryTokenInfoMainnet, + chainId: 1, + protocolMagic: 764_824_073, + eras: [byronEraConfig, shelleyEraConfig], + name: 'Mainnet', + isMainnet: true, + + legacyApiBaseUrl: 'https://api.yoroiwallet.com/api', + }, + 250: { + network: Chain.Network.Preprod, + primaryTokenInfo: primaryTokenInfoAnyTestnet, + chainId: 0, + protocolMagic: 1, + eras: [shelleyPreprodEraConfig], + name: 'Preprod', + isMainnet: false, + + legacyApiBaseUrl: 'https://preprod-backend.yoroiwallet.com/api', + }, + 350: { + network: Chain.Network.Preview, + primaryTokenInfo: primaryTokenInfoAnyTestnet, + chainId: 0, + protocolMagic: 2, + eras: [shelleyEraConfig], + name: 'Preview', + isMainnet: false, + legacyApiBaseUrl: 'https://preview-backend.emurgornd.com/api', + }, +}; From 9c9cfd92ff58c5cad844fe472ff86123e7384fc0 Mon Sep 17 00:00:00 2001 From: Sorin Chis Date: Fri, 28 Feb 2025 12:50:50 +0200 Subject: [PATCH 2/2] fix hidden amount observer --- .../common/components/HeaderPrice.tsx | 11 ++- .../common/components/PortfolioHeader.tsx | 6 +- .../TokenDetails/HeaderDetails/Header.tsx | 6 +- .../useCases/TokenDetails/TokenDetails.tsx | 67 ++++++++++--------- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/packages/yoroi-extension/app/UI/features/portfolio/common/components/HeaderPrice.tsx b/packages/yoroi-extension/app/UI/features/portfolio/common/components/HeaderPrice.tsx index a2f08eaf1d..3f8759045b 100644 --- a/packages/yoroi-extension/app/UI/features/portfolio/common/components/HeaderPrice.tsx +++ b/packages/yoroi-extension/app/UI/features/portfolio/common/components/HeaderPrice.tsx @@ -1,10 +1,11 @@ import { Skeleton, Typography } from '@mui/material'; +import { observer } from 'mobx-react'; import React from 'react'; import { usePortfolio } from '../../module/PortfolioContextProvider'; import { HiddenAmount } from './HiddenAmount'; -export const HeaderPrice = ({ isLoading = false }) => { - const { accountPair, isHiddenAmount } = usePortfolio(); +export const HeaderPrice = observer(({ isLoading = false, isHiddenAmount }) => { + const { accountPair } = usePortfolio(); if (isLoading) { return ; @@ -12,10 +13,8 @@ export const HeaderPrice = ({ isLoading = false }) => { return ( - - {accountPair?.to.value} - + {accountPair?.to.value}  {accountPair?.to.name} ); -}; +}); diff --git a/packages/yoroi-extension/app/UI/features/portfolio/common/components/PortfolioHeader.tsx b/packages/yoroi-extension/app/UI/features/portfolio/common/components/PortfolioHeader.tsx index bfb59e25d4..033cae7c3c 100644 --- a/packages/yoroi-extension/app/UI/features/portfolio/common/components/PortfolioHeader.tsx +++ b/packages/yoroi-extension/app/UI/features/portfolio/common/components/PortfolioHeader.tsx @@ -143,7 +143,11 @@ const PortfolioHeader = observer( - {loading || isLoading ? : } + {loading || isLoading ? ( + + ) : ( + + )} {isLoading || loading ? ( ) : ( diff --git a/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/HeaderDetails/Header.tsx b/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/HeaderDetails/Header.tsx index c2f3ddcf75..8e6d04bbc5 100644 --- a/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/HeaderDetails/Header.tsx +++ b/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/HeaderDetails/Header.tsx @@ -23,7 +23,7 @@ const HeaderSection = observer( ({ tokenInfo, stores }: Props): JSX.Element => { const theme: any = useTheme(); const strings = useStrings(); - const { unitOfAccount, accountPair, primaryTokenInfo, isHiddenAmount } = usePortfolio(); + const { unitOfAccount, accountPair, primaryTokenInfo } = usePortfolio(); const isPrimaryToken: boolean = tokenInfo.id === '-'; // TODO refactor and remove this caluclation from here in the future - this should come from the main selected wallet context @@ -79,7 +79,7 @@ const HeaderSection = observer( - {tokenTotalAmount} + {tokenTotalAmount} - {isPrimaryToken ? ptValue : totaPriceCalc} + {isPrimaryToken ? ptValue : totaPriceCalc}  {isPrimaryToken && unitOfAccount === primaryTokenInfo.name ? DEFAULT_FIAT_PAIR : unitOfAccount} diff --git a/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/TokenDetails.tsx b/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/TokenDetails.tsx index ac46f4c714..dd125bc1da 100644 --- a/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/TokenDetails.tsx +++ b/packages/yoroi-extension/app/UI/features/portfolio/useCases/TokenDetails/TokenDetails.tsx @@ -1,5 +1,6 @@ import { Box, Divider, Stack } from '@mui/material'; import { styled, useTheme } from '@mui/material/styles'; +import { observer } from 'mobx-react'; import React from 'react'; import { BackButton, Card } from '../../../../components'; import NavigationButton from '../../common/components/NavigationButton'; @@ -23,38 +24,40 @@ interface Props { stores: any; } -const TokenDetails = ({ tokenInfo, stores }: Props): JSX.Element => { - const theme: any = useTheme(); - const navigateTo = useNavigateTo(); - const strings = useStrings(); - const isPrimaryToken: boolean = tokenInfo.id === '-'; - - return ( - -
- navigateTo.portfolio()} /> - - navigateTo.swapPage(tokenInfo.info.id)} label={strings.swap} /> - navigateTo.sendPage()} label={strings.send} /> - navigateTo.receivePage()} label={strings.receive} /> +const TokenDetails = observer( + ({ tokenInfo, stores }: Props): JSX.Element => { + const theme: any = useTheme(); + const navigateTo = useNavigateTo(); + const strings = useStrings(); + const isPrimaryToken: boolean = tokenInfo.id === '-'; + + return ( + +
+ navigateTo.portfolio()} /> + + navigateTo.swapPage(tokenInfo.info.id)} label={strings.swap} /> + navigateTo.sendPage()} label={strings.send} /> + navigateTo.receivePage()} label={strings.receive} /> + +
+ + + + + + + + + + + + + {/* */} -
- - - - - - - - - - - - - {/* */} - -
- ); -}; + + ); + } +); export default TokenDetails;