diff --git a/packages/backend/src/Application.ts b/packages/backend/src/Application.ts index 7a6f0c8b6..94129aa75 100644 --- a/packages/backend/src/Application.ts +++ b/packages/backend/src/Application.ts @@ -89,7 +89,6 @@ import { FeederGatewayClient } from './peripherals/starkware/FeederGatewayClient import { FetchClient } from './peripherals/starkware/FetchClient' import { handleServerError, reportError } from './tools/ErrorReporter' import { Logger } from './tools/Logger' -import { shouldShowL2Transactions } from './utils/shouldShowL2Transactions' export class Application { start: () => Promise diff --git a/packages/backend/src/api/controllers/ForcedTradeOfferController.test.ts b/packages/backend/src/api/controllers/ForcedTradeOfferController.test.ts index 32ad20340..294e9325d 100644 --- a/packages/backend/src/api/controllers/ForcedTradeOfferController.test.ts +++ b/packages/backend/src/api/controllers/ForcedTradeOfferController.test.ts @@ -54,6 +54,7 @@ describe(ForcedTradeOfferController.name, () => { const pageContext: PageContext = { user: undefined, tradingMode: 'perpetual', + showL2Transactions: true, chainId: 1, instanceName: 'dYdX', collateralAsset: fakeCollateralAsset, diff --git a/packages/backend/src/core/PageContextService.test.ts b/packages/backend/src/core/PageContextService.test.ts index 0d309aec6..4e8b9791e 100644 --- a/packages/backend/src/core/PageContextService.test.ts +++ b/packages/backend/src/core/PageContextService.test.ts @@ -45,6 +45,7 @@ describe(PageContextService.name, () => { expect(context).toEqual({ user: undefined, tradingMode: 'perpetual', + showL2Transactions: true, chainId: 1, instanceName: perpetualConfig.starkex.instanceName, collateralAsset: fakeCollateralAsset, @@ -69,6 +70,7 @@ describe(PageContextService.name, () => { expect(context).toEqual({ user: undefined, tradingMode: 'spot', + showL2Transactions: true, chainId: 5, instanceName: spotConfig.starkex.instanceName, }) @@ -90,6 +92,7 @@ describe(PageContextService.name, () => { user: givenUser, tradingMode: 'perpetual', chainId: 1, + showL2Transactions: true, instanceName: spotConfig.starkex.instanceName, collateralAsset: fakeCollateralAsset, } as const @@ -110,6 +113,7 @@ describe(PageContextService.name, () => { ({ user: undefined, tradingMode: 'perpetual', + showL2Transactions: true, chainId: 1, instanceName: spotConfig.starkex.instanceName, collateralAsset: fakeCollateralAsset, @@ -138,6 +142,7 @@ describe(PageContextService.name, () => { user: givenUser, tradingMode: 'perpetual', chainId: 1, + showL2Transactions: true, instanceName: spotConfig.starkex.instanceName, collateralAsset: fakeCollateralAsset, } as const @@ -178,6 +183,7 @@ describe(PageContextService.name, () => { user: givenUser, tradingMode: 'perpetual', chainId: 1, + showL2Transactions: true, instanceName: spotConfig.starkex.instanceName, collateralAsset: fakeCollateralAsset, } as const @@ -200,6 +206,7 @@ describe(PageContextService.name, () => { const pageContext = { user: undefined, tradingMode: 'perpetual', + showL2Transactions: true, chainId: 5, instanceName: spotConfig.starkex.instanceName, collateralAsset: fakeCollateralAsset, @@ -218,6 +225,7 @@ describe(PageContextService.name, () => { const pageContext = { user: undefined, tradingMode: 'spot', + showL2Transactions: true, chainId: 5, instanceName: spotConfig.starkex.instanceName, } as const diff --git a/packages/frontend/src/preview/routes.ts b/packages/frontend/src/preview/routes.ts index 0e2ea3891..949d909dd 100644 --- a/packages/frontend/src/preview/routes.ts +++ b/packages/frontend/src/preview/routes.ts @@ -126,6 +126,8 @@ const routes: Route[] = [ totalStateUpdates: 5123, forcedTransactions: repeat(6, randomHomeForcedTransactionEntry), totalForcedTransactions: 68, + l2Transactions: [], + totalL2Transactions: 0, offers: repeat(6, randomHomeOfferEntry), totalOffers: 7, }) @@ -136,16 +138,16 @@ const routes: Route[] = [ description: 'The home page for project that shared feeder gateway with us.', render: (ctx) => { - const context = getPerpetualPageContext(ctx) + const context = getPerpetualPageContext(ctx, { + showL2Transactions: true, + }) ctx.body = renderHomePage({ context, stateUpdates: repeat(6, randomHomeStateUpdateEntry), totalStateUpdates: 5123, - l2Transactions: { - data: repeat(6, randomPerpetualL2TransactionEntry), - total: 5123, - }, + l2Transactions: repeat(6, randomPerpetualL2TransactionEntry), + totalL2Transactions: 5123, tutorials: [], forcedTransactions: repeat(6, randomHomeForcedTransactionEntry), totalForcedTransactions: 68, @@ -166,6 +168,8 @@ const routes: Route[] = [ totalStateUpdates: 5123, forcedTransactions: repeat(6, randomHomeForcedTransactionEntry), totalForcedTransactions: 68, + l2Transactions: [], + totalL2Transactions: 0, offers: repeat(6, randomHomeOfferEntry), totalOffers: 7, }) @@ -290,6 +294,8 @@ const routes: Route[] = [ Number(ethereumTimestamp) - Math.random() * 12 * 60 * 60 * 1000 ) ), + l2Transactions: [], + totalL2Transactions: 0, balanceChanges: repeat(10, randomStateUpdateBalanceChangeEntry), priceChanges: repeat(15, randomStateUpdatePriceEntry), totalBalanceChanges: 231, @@ -304,7 +310,9 @@ const routes: Route[] = [ description: 'State update page with l2 transacitons.', render: (ctx) => { const ethereumTimestamp = randomTimestamp() - const context = getPerpetualPageContext(ctx) + const context = getPerpetualPageContext(ctx, { + showL2Transactions: true, + }) ctx.body = renderStateUpdatePage({ context, id: randomId(), @@ -325,10 +333,8 @@ const routes: Route[] = [ balanceChanges: repeat(10, randomStateUpdateBalanceChangeEntry), priceChanges: repeat(15, randomStateUpdatePriceEntry), totalBalanceChanges: 231, - l2Transactions: { - data: repeat(5, randomPerpetualL2TransactionEntry), - total: 1000, - }, + l2Transactions: repeat(5, randomPerpetualL2TransactionEntry), + totalL2Transactions: 1000, transactions: repeat(5, randomStateUpdateTransactionEntry), totalTransactions: 5, }) @@ -398,7 +404,9 @@ const routes: Route[] = [ path: '/users/recover', description: 'Stark key recovery page, the stark key is not known.', render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) ctx.body = renderUserRecoverPage({ context, }) @@ -409,7 +417,9 @@ const routes: Route[] = [ description: 'Stark key register page, the stark key is known but not registered.', render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) ctx.body = renderUserRegisterPage({ context: { @@ -428,7 +438,9 @@ const routes: Route[] = [ description: 'My user page, the stark key is known, but it’s not registered.', render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) const starkKey = context.user.starkKey ?? StarkKey.fake() ctx.body = renderUserPage({ @@ -449,6 +461,8 @@ const routes: Route[] = [ totalBalanceChanges: 3367, transactions: repeat(10, randomUserTransactionEntry), totalTransactions: 48, + l2Transactions: [], + totalL2Transactions: 0, offers: repeat(6, randomUserOfferEntry), totalOffers: 6, }) @@ -458,7 +472,9 @@ const routes: Route[] = [ path: '/users/me/registered', description: 'My user page, the stark key is known and registered.', render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) const starkKey = context.user.starkKey ?? StarkKey.fake() ctx.body = renderUserPage({ @@ -480,6 +496,8 @@ const routes: Route[] = [ totalBalanceChanges: 3367, transactions: repeat(10, randomUserTransactionEntry), totalTransactions: 48, + l2Transactions: [], + totalL2Transactions: 0, offers: repeat(6, randomUserOfferEntry), totalOffers: 6, }) @@ -506,6 +524,8 @@ const routes: Route[] = [ totalBalanceChanges: 3367, transactions: repeat(10, randomUserTransactionEntry), totalTransactions: 48, + l2Transactions: [], + totalL2Transactions: 0, offers: repeat(6, randomUserOfferEntry), totalOffers: 6, }) @@ -517,7 +537,9 @@ const routes: Route[] = [ description: 'Someone else’s user page for project that feeder gateway with us.', render: (ctx) => { - const context = getPerpetualPageContext(ctx) + const context = getPerpetualPageContext(ctx, { + showL2Transactions: true, + }) ctx.body = renderUserPage({ context, @@ -532,10 +554,8 @@ const routes: Route[] = [ totalBalanceChanges: 3367, transactions: repeat(10, randomUserTransactionEntry), totalTransactions: 48, - l2Transactions: { - data: repeat(6, randomPerpetualUserL2TransactionEntry), - total: 5123, - }, + l2Transactions: repeat(6, randomPerpetualUserL2TransactionEntry), + totalL2Transactions: 5123, offers: repeat(6, randomUserOfferEntry), totalOffers: 6, }) @@ -923,7 +943,9 @@ const routes: Route[] = [ path: '/forced/new/spot/withdraw', description: 'Form to create a new spot forced withdrawal.', render: (ctx) => { - const context = getSpotPageContext(ctx, true) + const context = getSpotPageContext(ctx, { + fallbackToFakeUser: true, + }) ctx.body = renderNewSpotForcedWithdrawPage({ context, starkKey: StarkKey.fake(), @@ -941,7 +963,9 @@ const routes: Route[] = [ path: '/forced/new/perpetual/withdraw', description: 'Form to create a new perpetual forced withdrawal.', render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) ctx.body = renderNewPerpetualForcedActionPage({ context, starkKey: StarkKey.fake(), @@ -959,7 +983,9 @@ const routes: Route[] = [ path: '/forced/new/perpetual/buy', description: 'Form to create a new perpetual forced buy.', render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) ctx.body = renderNewPerpetualForcedActionPage({ context, starkKey: StarkKey.fake(), @@ -978,7 +1004,9 @@ const routes: Route[] = [ description: 'Form to create a new perpetual forced sell.', breakAfter: true, render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) ctx.body = renderNewPerpetualForcedActionPage({ context, starkKey: StarkKey.fake(), @@ -1179,7 +1207,9 @@ const routes: Route[] = [ 'Offer view of a created perpetual forced trade. As viewed by the creator.', isOfferPage: true, render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) const offer = randomOfferDetails() ctx.body = renderOfferAndForcedTradePage({ context, @@ -1200,7 +1230,9 @@ const routes: Route[] = [ isOfferPage: true, render: (ctx) => { const offer = randomOfferDetails() - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) const taker = { ethereumAddress: context.user.address, starkKey: context.user.starkKey, @@ -1237,7 +1269,9 @@ const routes: Route[] = [ 'Offer view of an accepted perpetual forced trade. As viewed by the creator.', isOfferPage: true, render: (ctx) => { - const context = getPerpetualPageContext(ctx, true) + const context = getPerpetualPageContext(ctx, { + fallbackToFakeUser: true, + }) const maker = userParty(context.user) const taker = randomParty() const offer = randomOfferDetails() @@ -1556,20 +1590,31 @@ function getFakeUser() { function getPerpetualPageContext( ctx: Koa.Context, - fallbackToFakeUser: true + options?: { + fallbackToFakeUser?: true + showL2Transactions?: boolean + } ): PageContextWithUser<'perpetual'> function getPerpetualPageContext( ctx: Koa.Context, - fallbackToFakeUser?: false + options?: { + fallbackToFakeUser?: false + showL2Transactions?: boolean + } ): PageContext<'perpetual'> function getPerpetualPageContext( ctx: Koa.Context, - fallbackToFakeUser?: boolean + options?: { + fallbackToFakeUser?: boolean + showL2Transactions?: boolean + } ): PageContextWithUser<'perpetual'> | PageContext<'perpetual'> { - const user = getUser(ctx) ?? (fallbackToFakeUser ? getFakeUser() : undefined) + const user = + getUser(ctx) ?? (options?.fallbackToFakeUser ? getFakeUser() : undefined) return { user, + showL2Transactions: options?.showL2Transactions ?? false, instanceName: 'dYdX', chainId: 1, tradingMode: 'perpetual', @@ -1579,20 +1624,31 @@ function getPerpetualPageContext( function getSpotPageContext( ctx: Koa.Context, - fallbackToFakeUser: true + options?: { + fallbackToFakeUser?: true + showL2Transactions?: boolean + } ): PageContextWithUser<'spot'> function getSpotPageContext( ctx: Koa.Context, - fallbackToFakeUser?: false + options?: { + fallbackToFakeUser?: false + showL2Transactions?: boolean + } ): PageContext<'spot'> function getSpotPageContext( ctx: Koa.Context, - fallbackToFakeUser?: boolean + options?: { + fallbackToFakeUser?: boolean + showL2Transactions?: boolean + } ): PageContextWithUser<'spot'> | PageContext<'spot'> { - const user = getUser(ctx) ?? (fallbackToFakeUser ? getFakeUser() : undefined) + const user = + getUser(ctx) ?? (options?.fallbackToFakeUser ? getFakeUser() : undefined) return { user, + showL2Transactions: options?.showL2Transactions ?? false, instanceName: 'Myria', chainId: 1, tradingMode: 'spot', diff --git a/packages/frontend/src/view/components/table/TablePreview.tsx b/packages/frontend/src/view/components/table/TablePreview.tsx index 7481cf1b4..87ee08f4e 100644 --- a/packages/frontend/src/view/components/table/TablePreview.tsx +++ b/packages/frontend/src/view/components/table/TablePreview.tsx @@ -1,4 +1,4 @@ -import { isNumber } from 'lodash' +import isNumber from 'lodash/isNumber' import React, { ReactNode } from 'react' import { formatInt } from '../../../utils/formatting/formatAmount' diff --git a/packages/frontend/src/view/components/table/TableWithPagination.tsx b/packages/frontend/src/view/components/table/TableWithPagination.tsx index 9c93c1e1f..0ec90e09c 100644 --- a/packages/frontend/src/view/components/table/TableWithPagination.tsx +++ b/packages/frontend/src/view/components/table/TableWithPagination.tsx @@ -1,4 +1,4 @@ -import { isNumber } from 'lodash' +import isNumber from 'lodash/isNumber' import React, { ReactNode } from 'react' import { formatInt } from '../../../utils/formatting/formatAmount'