Skip to content

Commit

Permalink
Merge pull request #795 from hermeznetwork/Refine-all-the-domain-inte…
Browse files Browse the repository at this point in the history
…rfaces-against-the-API-schemas

Refine all the domain interfaces against the api schemas
  • Loading branch information
amonsosanz authored Jan 11, 2022
2 parents 2f7fc44 + 42c69a8 commit 3aea97f
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 132 deletions.
Binary file modified public/favicon.ico
Binary file not shown.
Binary file modified public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export type {
Exit,
FiatExchangeRates,
HermezApiResourceItem,
HermezNetworkStatus,
HermezStatus,
HermezWallet,
HistoryTransaction,
ISOStringDate,
Expand All @@ -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;
Expand Down
26 changes: 1 addition & 25 deletions src/images/hermez-logo-alternative.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 1 addition & 7 deletions src/images/hermez-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/persistence/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const token = StrictSchema<Token>()(
id: z.number(),
name: z.string(),
symbol: z.string(),
USD: z.number(),
USD: z.number().nullable(),
})
)
);
Expand Down Expand Up @@ -71,9 +71,9 @@ const historyTransaction = StrictSchema<HistoryTransaction>()(
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(),
Expand Down
6 changes: 3 additions & 3 deletions src/store/global/global.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CoordinatorState,
EthereumNetwork,
FiatExchangeRates,
HermezNetworkStatus,
NetworkStatus,
HermezWallet,
ISOStringDate,
PendingDelayedWithdraw,
Expand Down Expand Up @@ -131,7 +131,7 @@ export interface CloseSnackbar {

export interface ChangeNetworkStatus {
type: GlobalActionTypes.CHANGE_NETWORK_STATUS;
networkStatus: HermezNetworkStatus;
networkStatus: NetworkStatus;
}

export interface AddPendingWithdraw {
Expand Down Expand Up @@ -416,7 +416,7 @@ function closeSnackbar(): CloseSnackbar {
};
}

function changeNetworkStatus(networkStatus: HermezNetworkStatus): ChangeNetworkStatus {
function changeNetworkStatus(networkStatus: NetworkStatus): ChangeNetworkStatus {
return {
type: GlobalActionTypes.CHANGE_NETWORK_STATUS,
networkStatus,
Expand Down
4 changes: 2 additions & 2 deletions src/store/global/global.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CoordinatorState,
EthereumNetwork,
FiatExchangeRates,
HermezNetworkStatus,
NetworkStatus,
HermezStatus,
HermezWallet,
PendingDelayedWithdraws,
Expand Down Expand Up @@ -59,7 +59,7 @@ export interface GlobalState {
redirectRoute: string;
fiatExchangeRatesTask: AsyncTask<FiatExchangeRates, string>;
snackbar: SnackbarState;
networkStatus: HermezNetworkStatus;
networkStatus: NetworkStatus;
pendingWithdraws: PendingWithdraws;
pendingDelayedWithdraws: PendingDelayedWithdraws;
timerWithdraws: TimerWithdraws;
Expand Down
9 changes: 3 additions & 6 deletions src/store/global/global.thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
CoordinatorState,
Exit,
FiatExchangeRates,
HermezNetworkStatus,
NetworkStatus,
HistoryTransaction,
ISOStringDate,
PendingDelayedWithdraw,
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -857,7 +854,7 @@ function checkPendingTransactions(): AppThunk {
? { to: transaction.toHezEthereumAddress }
: transaction.type === TxType.Transfer
? { to: transaction.toAccountIndex }
: {}),
: { to: null }),
fee: transaction.fee,
};

Expand Down
1 change: 1 addition & 0 deletions src/store/transactions/exit/exit.thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
75 changes: 34 additions & 41 deletions src/types/hermezjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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<string, number>;

export interface HermezApiResourceItem {
Expand All @@ -34,17 +27,17 @@ declare module "@hermeznetwork/*" {
id: number;
name: string;
symbol: string;
USD: number;
// fiatUpdate: ISOStringDate;
USD: number | null;
// fiatUpdate: ISOStringDate | null;
};

export interface L1Info {
// amountSuccess: boolean;
depositAmount: string;
// depositAmountSuccess: boolean;
// ethereumBlockNum: number;
// historicDepositAmountUSD: number;
// toForgeL1TransactionsNum: number;
// historicDepositAmountUSD: number | null;
// toForgeL1TransactionsNum: number | null;
// userOrigin: boolean;
}

Expand Down Expand Up @@ -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";
Expand All @@ -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;
};

Expand Down Expand Up @@ -158,7 +151,7 @@ declare module "@hermeznetwork/*" {

// interface CollectedFees;

type LastBatch = HermezApiResourceItem & {
type Batch = HermezApiResourceItem & {
// batchNum: number;
// ethereumTxHash: string;
// ethereumBlockNum: number;
Expand Down Expand Up @@ -186,8 +179,8 @@ declare module "@hermeznetwork/*" {
// slotNum: number;
// fromBlock: number;
// toBlock: number;
// fromTimestamp: string;
toTimestamp: string;
// fromTimestamp: ISOStringDate;
toTimestamp: ISOStringDate;
}

export interface NextForger {
Expand All @@ -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 {
Expand Down Expand Up @@ -238,7 +231,7 @@ declare module "@hermeznetwork/*" {
// bootCoordinator: string;
// bootCoordinatorUrl: string;
// defaultSlotSetBid: string[];
// defaultSlotSetBidSlotNum: number;
// defaultSlotSetBidSlotNum?: number;
// closedAuctionSlots: number;
// openAuctionSlots: number;
// allocationRatio: number[];
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/utils/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,24 @@ 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);
}

/**
* 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;
Expand All @@ -97,7 +103,7 @@ function convertTokenAmountToFiat(
const fixedTokenAmount = getFixedTokenAmount(tokenAmount, token.decimals);
return getTokenAmountInPreferredCurrency(
fixedTokenAmount,
token.USD,
token,
preferredCurrency,
fiatExchangeRates
);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion src/views/account-details/account-details.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function AccountDetails({

return getTokenAmountInPreferredCurrency(
accountTokenBalance,
account.token.USD,
account.token,
preferredCurrency,
fiatExchangeRatesTask.data
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function TransactionList({
fromAccountIndex={
isPendingDeposit(transaction)
? transaction.accountIndex
: transaction.fromAccountIndex
: transaction.fromAccountIndex || undefined
}
amount={fixedTokenAmount}
tokenSymbol={transaction.token.symbol}
Expand All @@ -78,7 +78,7 @@ function TransactionList({
)
: getTokenAmountInPreferredCurrency(
fixedTokenAmount,
transaction.token.USD,
transaction.token,
preferredCurrency,
fiatExchangeRates
)
Expand Down
Loading

0 comments on commit 3aea97f

Please sign in to comment.