diff --git a/public/favicon.ico b/public/favicon.ico index da2a843c3..9a2b3d3fa 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/logo192.png b/public/logo192.png index 239149a91..93539aca9 100644 Binary files a/public/logo192.png and b/public/logo192.png differ diff --git a/src/domain/index.ts b/src/domain/index.ts index 72c7fd6d0..cedc74df1 100644 --- a/src/domain/index.ts +++ b/src/domain/index.ts @@ -13,8 +13,6 @@ export type { Exit, FiatExchangeRates, HermezApiResourceItem, - HermezNetworkStatus, - HermezStatus, HermezWallet, HistoryTransaction, ISOStringDate, @@ -28,6 +26,12 @@ export type { Token, } from "@hermeznetwork/hermezjs"; +export type NetworkStatus = "online" | "offline"; + +export interface HermezStatus { + isUnderMaintenance: boolean; +} + export interface EthereumNetwork { chainId: number; name: string; diff --git a/src/images/hermez-logo-alternative.svg b/src/images/hermez-logo-alternative.svg index 42f593c61..305eca183 100644 --- a/src/images/hermez-logo-alternative.svg +++ b/src/images/hermez-logo-alternative.svg @@ -1,25 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/images/hermez-logo.svg b/src/images/hermez-logo.svg index f0f0bfb43..572e2a7fd 100644 --- a/src/images/hermez-logo.svg +++ b/src/images/hermez-logo.svg @@ -1,7 +1 @@ - - - - - - - + \ No newline at end of file diff --git a/src/persistence/parsers/index.ts b/src/persistence/parsers/index.ts index 71b7503a7..00677271b 100644 --- a/src/persistence/parsers/index.ts +++ b/src/persistence/parsers/index.ts @@ -34,7 +34,7 @@ const token = StrictSchema()( id: z.number(), name: z.string(), symbol: z.string(), - USD: z.number(), + USD: z.number().nullable(), }) ) ); @@ -71,9 +71,9 @@ const historyTransaction = StrictSchema()( hermezApiResourceItem.and( z.object({ amount: z.string(), - batchNum: z.number(), - fromAccountIndex: z.string(), - fromHezEthereumAddress: z.string(), + batchNum: z.number().nullable(), + fromAccountIndex: z.string().nullable(), + fromHezEthereumAddress: z.string().nullable(), historicUSD: z.number().nullable(), id: z.string(), L1Info: l1Info.nullable(), diff --git a/src/store/global/global.actions.ts b/src/store/global/global.actions.ts index fac9b7246..56acc4fbc 100644 --- a/src/store/global/global.actions.ts +++ b/src/store/global/global.actions.ts @@ -4,7 +4,7 @@ import { CoordinatorState, EthereumNetwork, FiatExchangeRates, - HermezNetworkStatus, + NetworkStatus, HermezWallet, ISOStringDate, PendingDelayedWithdraw, @@ -131,7 +131,7 @@ export interface CloseSnackbar { export interface ChangeNetworkStatus { type: GlobalActionTypes.CHANGE_NETWORK_STATUS; - networkStatus: HermezNetworkStatus; + networkStatus: NetworkStatus; } export interface AddPendingWithdraw { @@ -416,7 +416,7 @@ function closeSnackbar(): CloseSnackbar { }; } -function changeNetworkStatus(networkStatus: HermezNetworkStatus): ChangeNetworkStatus { +function changeNetworkStatus(networkStatus: NetworkStatus): ChangeNetworkStatus { return { type: GlobalActionTypes.CHANGE_NETWORK_STATUS, networkStatus, diff --git a/src/store/global/global.reducer.ts b/src/store/global/global.reducer.ts index 7acfd07fc..154d76081 100644 --- a/src/store/global/global.reducer.ts +++ b/src/store/global/global.reducer.ts @@ -6,7 +6,7 @@ import { CoordinatorState, EthereumNetwork, FiatExchangeRates, - HermezNetworkStatus, + NetworkStatus, HermezStatus, HermezWallet, PendingDelayedWithdraws, @@ -59,7 +59,7 @@ export interface GlobalState { redirectRoute: string; fiatExchangeRatesTask: AsyncTask; snackbar: SnackbarState; - networkStatus: HermezNetworkStatus; + networkStatus: NetworkStatus; pendingWithdraws: PendingWithdraws; pendingDelayedWithdraws: PendingDelayedWithdraws; timerWithdraws: TimerWithdraws; diff --git a/src/store/global/global.thunks.ts b/src/store/global/global.thunks.ts index 2a78c77a3..e7ebe26d8 100644 --- a/src/store/global/global.thunks.ts +++ b/src/store/global/global.thunks.ts @@ -27,7 +27,7 @@ import { CoordinatorState, Exit, FiatExchangeRates, - HermezNetworkStatus, + NetworkStatus, HistoryTransaction, ISOStringDate, PendingDelayedWithdraw, @@ -115,10 +115,7 @@ function fetchFiatExchangeRates(): AppThunk { /** * Changes the current network status of the application */ -function changeNetworkStatus( - newNetworkStatus: HermezNetworkStatus, - backgroundColor: string -): AppThunk { +function changeNetworkStatus(newNetworkStatus: NetworkStatus, backgroundColor: string): AppThunk { return (dispatch: AppDispatch, getState: () => AppState) => { const { global: { networkStatus: previousNetworkStatus }, @@ -857,7 +854,7 @@ function checkPendingTransactions(): AppThunk { ? { to: transaction.toHezEthereumAddress } : transaction.type === TxType.Transfer ? { to: transaction.toAccountIndex } - : {}), + : { to: null }), fee: transaction.fee, }; diff --git a/src/store/transactions/exit/exit.thunks.ts b/src/store/transactions/exit/exit.thunks.ts index 11c70faca..528ac6c27 100644 --- a/src/store/transactions/exit/exit.thunks.ts +++ b/src/store/transactions/exit/exit.thunks.ts @@ -177,6 +177,7 @@ function exit(amount: BigNumber, account: HermezAccount, fee: BigNumber) { const txData = { type: TxType.Exit, from: account.accountIndex, + to: null, amount: HermezCompressedAmount.compressAmount(amount.toString()), fee: feeBigIntToNumber(fee, account.token), }; diff --git a/src/types/hermezjs.d.ts b/src/types/hermezjs.d.ts index 812c84dd3..5555499d7 100644 --- a/src/types/hermezjs.d.ts +++ b/src/types/hermezjs.d.ts @@ -2,10 +2,9 @@ * HermezJS Type Definitions * * Some types and props are currently commented because are not used by this app. - * As we proceed with the migration of the application to typescript, more - * properties and types will likely be required. We can uncomment them as - * required and finally remove all those not required. - */ + * They are kept in case we eventually decide to move this typings file to the + * HermezJS library to enable it with TypeScript support. + * */ declare module "@hermeznetwork/*" { import { TxState, TxType } from "@hermeznetwork/hermezjs/src/enums"; @@ -15,12 +14,6 @@ declare module "@hermeznetwork/*" { export type ISOStringDate = string; - export interface HermezStatus { - isUnderMaintenance: boolean; - } - - export type HermezNetworkStatus = "online" | "offline"; - export type FiatExchangeRates = Record; export interface HermezApiResourceItem { @@ -34,8 +27,8 @@ declare module "@hermeznetwork/*" { id: number; name: string; symbol: string; - USD: number; - // fiatUpdate: ISOStringDate; + USD: number | null; + // fiatUpdate: ISOStringDate | null; }; export interface L1Info { @@ -43,8 +36,8 @@ declare module "@hermeznetwork/*" { depositAmount: string; // depositAmountSuccess: boolean; // ethereumBlockNum: number; - // historicDepositAmountUSD: number; - // toForgeL1TransactionsNum: number; + // historicDepositAmountUSD: number | null; + // toForgeL1TransactionsNum: number | null; // userOrigin: boolean; } @@ -81,14 +74,14 @@ declare module "@hermeznetwork/*" { }; export type HistoryTransaction = HermezApiResourceItem & { - batchNum: number; - fromAccountIndex: string; - fromHezEthereumAddress: string; + batchNum: number | null; + fromAccountIndex: string | null; + fromHezEthereumAddress: string | null; id: string; toHezEthereumAddress: string | null; type: TxType; amount: string; - // fromBJJ: string; + // fromBJJ: string | null; historicUSD: number | null; L1Info: L1Info | null; L1orL2: "L1" | "L2"; @@ -102,32 +95,32 @@ declare module "@hermeznetwork/*" { export type PoolTransaction = HermezApiResourceItem & { amount: string; - errorCode: number | null; + errorCode?: number | null; fee: number; fromAccountIndex: string; - fromBJJ: string; - fromHezEthereumAddress: string; + fromBJJ: string | null; + fromHezEthereumAddress: string | null; state: TxState; timestamp: ISOStringDate; - toAccountIndex: string; + toAccountIndex: string | null; toBJJ: string | null; - toHezEthereumAddress: string; + toHezEthereumAddress: string | null; token: Token; type: TxType; - batchNum: number | null; + batchNum?: number | null; id: string; - // errorType: string | null; + // errorType?: string | null; // info: string | null; - // maxNumBatch: number; + // maxNumBatch?: number; // nonce: number; - // requestAmount: unknown | null; - // requestFee: unknown | null; - // requestFromAccountIndex: unknown | null; - // requestNonce: unknown | null; - // requestToAccountIndex: unknown | null; - // requestToBJJ: unknown | null; - // requestToHezEthereumAddress: unknown | null; - // requestTokenId: unknown | null; + // requestAmount: string | null; + // requestFee: number | null; + // requestFromAccountIndex: string | null; + // requestNonce: number | null; + // requestToAccountIndex: string | null; + // requestToBJJ: string | null; + // requestToHezEthereumAddress: string | null; + // requestTokenId: number | null; // signature: string; }; @@ -158,7 +151,7 @@ declare module "@hermeznetwork/*" { // interface CollectedFees; - type LastBatch = HermezApiResourceItem & { + type Batch = HermezApiResourceItem & { // batchNum: number; // ethereumTxHash: string; // ethereumBlockNum: number; @@ -186,8 +179,8 @@ declare module "@hermeznetwork/*" { // slotNum: number; // fromBlock: number; // toBlock: number; - // fromTimestamp: string; - toTimestamp: string; + // fromTimestamp: ISOStringDate; + toTimestamp: ISOStringDate; } export interface NextForger { @@ -198,10 +191,10 @@ declare module "@hermeznetwork/*" { interface Network { // lastEthereumBlock: number; // lastSynchedBlock: number; - lastBatch: LastBatch; + lastBatch: Batch; // currentSlot: number; nextForgers: NextForger[]; - // pendingL1Transactions: number; + // pendingL1Transactions?: number; } // interface Metrics { @@ -238,7 +231,7 @@ declare module "@hermeznetwork/*" { // bootCoordinator: string; // bootCoordinatorUrl: string; // defaultSlotSetBid: string[]; - // defaultSlotSetBidSlotNum: number; + // defaultSlotSetBidSlotNum?: number; // closedAuctionSlots: number; // openAuctionSlots: number; // allocationRatio: number[]; @@ -380,7 +373,7 @@ declare module "@hermeznetwork/hermezjs/src/tx" { interface Tx { type: TxType; from: string; - to?: string; + to: string | null; amount: HermezCompressedAmount; fee: number; nonce?: number; diff --git a/src/utils/currencies.ts b/src/utils/currencies.ts index e23b638d5..36a51ad1a 100644 --- a/src/utils/currencies.ts +++ b/src/utils/currencies.ts @@ -68,11 +68,14 @@ function getAmountInPreferredCurrency( */ function getTokenAmountInPreferredCurrency( amount: string, - usdTokenExchangeRate: number, + token: Token, preferredCurrency: string, fiatExchangeRates?: FiatExchangeRates ): number | undefined { - const usdAmount = Number(amount) * usdTokenExchangeRate; + if (!token.USD) { + return undefined; + } + const usdAmount = Number(amount) * token.USD; return getAmountInPreferredCurrency(usdAmount, preferredCurrency, fiatExchangeRates); } @@ -80,6 +83,9 @@ function getTokenAmountInPreferredCurrency( * Converts a fee index to USD */ function getFeeInUsd(feeIndex: number, amount: string, token: Token): number { + if (!token.USD) { + return 0; + } const feeInToken = Number(getTokenAmountString(getFeeValue(feeIndex, amount), token.decimals)); const feeInFiat = feeInToken * token.USD; return feeInFiat; @@ -97,7 +103,7 @@ function convertTokenAmountToFiat( const fixedTokenAmount = getFixedTokenAmount(tokenAmount, token.decimals); return getTokenAmountInPreferredCurrency( fixedTokenAmount, - token.USD, + token, preferredCurrency, fiatExchangeRates ); diff --git a/src/utils/fees.ts b/src/utils/fees.ts index 61d10c624..47d17e94d 100644 --- a/src/utils/fees.ts +++ b/src/utils/fees.ts @@ -36,7 +36,7 @@ type GetMinimumL2FeeParams = GetMinimumTransferFee | GetMinimumExitFee; function getMinimumL2Fee(params: GetMinimumL2FeeParams): BigNumber { const { txType, token, feesTask } = params; - if (!isAsyncTaskDataAvailable(feesTask) || token.USD === 0) { + if (!isAsyncTaskDataAvailable(feesTask) || !token.USD || token.USD === 0) { return BigNumber.from(0); } @@ -120,13 +120,13 @@ function getEstimatedWithdrawFee( const formattedWithdrawFee = getFixedTokenAmount(estimatedWithdrawFee.amount.toString()); const exitFeeInFiat = getTokenAmountInPreferredCurrency( formattedExitFee, - token.USD, + token, preferredCurrency, fiatExchangeRates ); const withdrawFeeInFiat = getTokenAmountInPreferredCurrency( formattedWithdrawFee, - estimatedWithdrawFee.token.USD, + estimatedWithdrawFee.token, preferredCurrency, fiatExchangeRates ); diff --git a/src/views/account-details/account-details.view.tsx b/src/views/account-details/account-details.view.tsx index 1b1d365a1..9a3a69f5e 100644 --- a/src/views/account-details/account-details.view.tsx +++ b/src/views/account-details/account-details.view.tsx @@ -246,7 +246,7 @@ function AccountDetails({ return getTokenAmountInPreferredCurrency( accountTokenBalance, - account.token.USD, + account.token, preferredCurrency, fiatExchangeRatesTask.data ); diff --git a/src/views/account-details/components/transaction-list/transaction-list.view.tsx b/src/views/account-details/components/transaction-list/transaction-list.view.tsx index 001adec10..573e2dd23 100644 --- a/src/views/account-details/components/transaction-list/transaction-list.view.tsx +++ b/src/views/account-details/components/transaction-list/transaction-list.view.tsx @@ -65,7 +65,7 @@ function TransactionList({ fromAccountIndex={ isPendingDeposit(transaction) ? transaction.accountIndex - : transaction.fromAccountIndex + : transaction.fromAccountIndex || undefined } amount={fixedTokenAmount} tokenSymbol={transaction.token.symbol} @@ -78,7 +78,7 @@ function TransactionList({ ) : getTokenAmountInPreferredCurrency( fixedTokenAmount, - transaction.token.USD, + transaction.token, preferredCurrency, fiatExchangeRates ) diff --git a/src/views/app.view.tsx b/src/views/app.view.tsx index 99a11e505..c2ac5172d 100644 --- a/src/views/app.view.tsx +++ b/src/views/app.view.tsx @@ -20,7 +20,7 @@ import { Theme } from "src/styles/theme"; import { EthereumNetwork, FiatExchangeRates, - HermezNetworkStatus, + NetworkStatus, HermezStatus, HermezWallet, } from "src/domain"; @@ -42,7 +42,7 @@ interface AppHandlerProps { onLoadCoordinatorState: () => void; onLoadFiatExchangeRates: () => void; onCheckHermezStatus: () => void; - onChangeNetworkStatus: (hermezNetworkStatus: HermezNetworkStatus, color: string) => void; + onChangeNetworkStatus: (networkStatus: NetworkStatus, color: string) => void; onDisconnectAccount: () => void; onCheckPendingTransactions: () => void; onReloadApp: () => void; diff --git a/src/views/home/components/pending-deposit-list/pending-deposit-list.view.tsx b/src/views/home/components/pending-deposit-list/pending-deposit-list.view.tsx index 7a54d48a0..a1cda7006 100644 --- a/src/views/home/components/pending-deposit-list/pending-deposit-list.view.tsx +++ b/src/views/home/components/pending-deposit-list/pending-deposit-list.view.tsx @@ -33,7 +33,7 @@ function PendingDepositList({ balance={deposit.amount} fiatBalance={getTokenAmountInPreferredCurrency( getFixedTokenAmount(deposit.amount, deposit.token.decimals), - deposit.token.USD, + deposit.token, preferredCurrency, fiatExchangeRates )} diff --git a/src/views/home/home.styles.ts b/src/views/home/home.styles.ts index e9aef792b..83d7b8a52 100644 --- a/src/views/home/home.styles.ts +++ b/src/views/home/home.styles.ts @@ -22,7 +22,6 @@ const useHomeStyles = createUseStyles((theme: Theme) => ({ color: theme.palette.grey.dark, fontSize: theme.spacing(1.75), fontWeight: theme.fontWeights.medium, - marginTop: -theme.spacing(2.5), marginBottom: 0, }, walletAddress: { diff --git a/src/views/shared/account-list/account-list.view.tsx b/src/views/shared/account-list/account-list.view.tsx index a658e2003..8fe3fb28c 100644 --- a/src/views/shared/account-list/account-list.view.tsx +++ b/src/views/shared/account-list/account-list.view.tsx @@ -50,7 +50,7 @@ function AccountList({ ); } else { - const from = { - subtitle: getPartiallyHiddenHermezAddress(transaction.fromHezEthereumAddress), - onCopyFromAddress: handleCopyFromAddress, - }; + const from = transaction.fromHezEthereumAddress + ? { + subtitle: getPartiallyHiddenHermezAddress(transaction.fromHezEthereumAddress), + onCopyFromAddress: handleCopyFromAddress, + } + : undefined; const to = { subtitle: "My Hermez address", value: transaction.toHezEthereumAddress @@ -174,9 +176,7 @@ function TransactionInfo({ from={myHermezAddress} to={{ subtitle: "My Ethereum address", - value: getPartiallyHiddenEthereumAddress( - getEthereumAddress(transaction.fromHezEthereumAddress) - ), + value: partiallyHiddenEthereumAddressOrNotAvailable(transaction.fromHezEthereumAddress), }} date={date} feeData={feeData} @@ -191,9 +191,7 @@ function TransactionInfo({ from={myHermezAddress} to={{ subtitle: "My Ethereum address", - value: getPartiallyHiddenEthereumAddress( - getEthereumAddress(transaction.fromHezEthereumAddress) - ), + value: partiallyHiddenEthereumAddressOrNotAvailable(transaction.fromHezEthereumAddress), }} date={date} /> @@ -205,4 +203,14 @@ function TransactionInfo({ } } +function partiallyHiddenHermezAddressOrNotAvailable(hezEthereumAddress: string | null): string { + return hezEthereumAddress ? getPartiallyHiddenHermezAddress(hezEthereumAddress) : "Not available"; +} + +function partiallyHiddenEthereumAddressOrNotAvailable(hezEthereumAddress: string | null): string { + return hezEthereumAddress + ? getPartiallyHiddenEthereumAddress(getEthereumAddress(hezEthereumAddress)) + : "Not available"; +} + export default TransactionInfo; diff --git a/src/views/transaction-details/transaction-details.view.tsx b/src/views/transaction-details/transaction-details.view.tsx index 057f79387..2b4f651a4 100644 --- a/src/views/transaction-details/transaction-details.view.tsx +++ b/src/views/transaction-details/transaction-details.view.tsx @@ -113,7 +113,7 @@ function TransactionDetails({ return getTokenAmountInPreferredCurrency( fixedAccountBalance, - token.USD, + token, preferredCurrency, fiatExchangeRatesTask.data ); @@ -127,7 +127,7 @@ function TransactionDetails({ function getHistoryTransactionFee(historyTransaction: HistoryTransaction): BigNumber | undefined { const { L2Info, token, amount } = historyTransaction; - if (!L2Info) { + if (!L2Info || !token.USD) { return undefined; } else if (L2Info.historicFeeUSD) { const feeUsd = L2Info.historicFeeUSD; @@ -142,6 +142,9 @@ function TransactionDetails({ function getPoolTransactionFee(poolTransaction: PoolTransaction): BigNumber | undefined { const { fee, token, amount } = poolTransaction; + if (!token.USD) { + return undefined; + } const feeUsd = getFeeInUsd(fee, amount, token); const feeToken = feeUsd / token.USD; return parseUnits(feeToken.toFixed(token.decimals), token.decimals); diff --git a/src/views/transactions/components/fee/fee.view.tsx b/src/views/transactions/components/fee/fee.view.tsx index 83d7911a6..d057cb403 100644 --- a/src/views/transactions/components/fee/fee.view.tsx +++ b/src/views/transactions/components/fee/fee.view.tsx @@ -57,7 +57,7 @@ function Fee(props: FeeProps): JSX.Element { const depositFeeInFiat = isAsyncTaskDataAvailable(estimatedDepositFeeTask) ? getTokenAmountInPreferredCurrency( formattedDepositFee, - estimatedDepositFeeTask.data.token.USD, + estimatedDepositFeeTask.data.token, preferredCurrency, isAsyncTaskDataAvailable(fiatExchangeRatesTask) ? fiatExchangeRatesTask.data : {} ) @@ -79,7 +79,7 @@ function Fee(props: FeeProps): JSX.Element { const formattedFee = getFixedTokenAmount(fee.toString(), token.decimals); const feeInFiat = getTokenAmountInPreferredCurrency( formattedFee, - token.USD, + token, preferredCurrency, isAsyncTaskDataAvailable(fiatExchangeRatesTask) ? fiatExchangeRatesTask.data : {} ); diff --git a/src/views/transactions/components/selected-account/selected-account.view.tsx b/src/views/transactions/components/selected-account/selected-account.view.tsx index 566aaa29d..e95ece76c 100644 --- a/src/views/transactions/components/selected-account/selected-account.view.tsx +++ b/src/views/transactions/components/selected-account/selected-account.view.tsx @@ -54,7 +54,7 @@ function SelectedAccount(props: SelectedAccountProps): JSX.Element { currency={preferredCurrency} amount={getTokenAmountInPreferredCurrency( getFixedTokenAmount(account.balance, account.token.decimals), - account.token.USD, + account.token, preferredCurrency, isAsyncTaskDataAvailable(fiatExchangeRatesTask) ? fiatExchangeRatesTask.data : {} )} diff --git a/src/views/transactions/components/transaction-overview/transaction-overview.view.tsx b/src/views/transactions/components/transaction-overview/transaction-overview.view.tsx index f3eab77f0..a132e0aa0 100644 --- a/src/views/transactions/components/transaction-overview/transaction-overview.view.tsx +++ b/src/views/transactions/components/transaction-overview/transaction-overview.view.tsx @@ -112,7 +112,7 @@ function TransactionOverview({ return getTokenAmountInPreferredCurrency( fixedAccountBalance, - token.USD, + token, preferredCurrency, fiatExchangeRates ); diff --git a/src/views/transactions/deposit/components/deposit-alert/deposit-alert.view.tsx b/src/views/transactions/deposit/components/deposit-alert/deposit-alert.view.tsx index ff0d2ceb2..2ed7f8e77 100644 --- a/src/views/transactions/deposit/components/deposit-alert/deposit-alert.view.tsx +++ b/src/views/transactions/deposit/components/deposit-alert/deposit-alert.view.tsx @@ -38,7 +38,7 @@ function DepositAlert({