Skip to content

Commit

Permalink
fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
torztomasz committed Jul 12, 2023
1 parent 180767f commit dc7c34d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 37 deletions.
1 change: 0 additions & 1 deletion packages/backend/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe(ForcedTradeOfferController.name, () => {
const pageContext: PageContext = {
user: undefined,
tradingMode: 'perpetual',
showL2Transactions: true,
chainId: 1,
instanceName: 'dYdX',
collateralAsset: fakeCollateralAsset,
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/core/PageContextService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe(PageContextService.name, () => {
expect(context).toEqual({
user: undefined,
tradingMode: 'perpetual',
showL2Transactions: true,
chainId: 1,
instanceName: perpetualConfig.starkex.instanceName,
collateralAsset: fakeCollateralAsset,
Expand All @@ -69,6 +70,7 @@ describe(PageContextService.name, () => {
expect(context).toEqual({
user: undefined,
tradingMode: 'spot',
showL2Transactions: true,
chainId: 5,
instanceName: spotConfig.starkex.instanceName,
})
Expand All @@ -90,6 +92,7 @@ describe(PageContextService.name, () => {
user: givenUser,
tradingMode: 'perpetual',
chainId: 1,
showL2Transactions: true,
instanceName: spotConfig.starkex.instanceName,
collateralAsset: fakeCollateralAsset,
} as const
Expand All @@ -110,6 +113,7 @@ describe(PageContextService.name, () => {
({
user: undefined,
tradingMode: 'perpetual',
showL2Transactions: true,
chainId: 1,
instanceName: spotConfig.starkex.instanceName,
collateralAsset: fakeCollateralAsset,
Expand Down Expand Up @@ -138,6 +142,7 @@ describe(PageContextService.name, () => {
user: givenUser,
tradingMode: 'perpetual',
chainId: 1,
showL2Transactions: true,
instanceName: spotConfig.starkex.instanceName,
collateralAsset: fakeCollateralAsset,
} as const
Expand Down Expand Up @@ -178,6 +183,7 @@ describe(PageContextService.name, () => {
user: givenUser,
tradingMode: 'perpetual',
chainId: 1,
showL2Transactions: true,
instanceName: spotConfig.starkex.instanceName,
collateralAsset: fakeCollateralAsset,
} as const
Expand All @@ -200,6 +206,7 @@ describe(PageContextService.name, () => {
const pageContext = {
user: undefined,
tradingMode: 'perpetual',
showL2Transactions: true,
chainId: 5,
instanceName: spotConfig.starkex.instanceName,
collateralAsset: fakeCollateralAsset,
Expand All @@ -218,6 +225,7 @@ describe(PageContextService.name, () => {
const pageContext = {
user: undefined,
tradingMode: 'spot',
showL2Transactions: true,
chainId: 5,
instanceName: spotConfig.starkex.instanceName,
} as const
Expand Down
124 changes: 90 additions & 34 deletions packages/frontend/src/preview/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ const routes: Route[] = [
totalStateUpdates: 5123,
forcedTransactions: repeat(6, randomHomeForcedTransactionEntry),
totalForcedTransactions: 68,
l2Transactions: [],
totalL2Transactions: 0,
offers: repeat(6, randomHomeOfferEntry),
totalOffers: 7,
})
Expand All @@ -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,
Expand All @@ -166,6 +168,8 @@ const routes: Route[] = [
totalStateUpdates: 5123,
forcedTransactions: repeat(6, randomHomeForcedTransactionEntry),
totalForcedTransactions: 68,
l2Transactions: [],
totalL2Transactions: 0,
offers: repeat(6, randomHomeOfferEntry),
totalOffers: 7,
})
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand All @@ -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: {
Expand All @@ -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({
Expand All @@ -449,6 +461,8 @@ const routes: Route[] = [
totalBalanceChanges: 3367,
transactions: repeat(10, randomUserTransactionEntry),
totalTransactions: 48,
l2Transactions: [],
totalL2Transactions: 0,
offers: repeat(6, randomUserOfferEntry),
totalOffers: 6,
})
Expand All @@ -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({
Expand All @@ -480,6 +496,8 @@ const routes: Route[] = [
totalBalanceChanges: 3367,
transactions: repeat(10, randomUserTransactionEntry),
totalTransactions: 48,
l2Transactions: [],
totalL2Transactions: 0,
offers: repeat(6, randomUserOfferEntry),
totalOffers: 6,
})
Expand All @@ -506,6 +524,8 @@ const routes: Route[] = [
totalBalanceChanges: 3367,
transactions: repeat(10, randomUserTransactionEntry),
totalTransactions: 48,
l2Transactions: [],
totalL2Transactions: 0,
offers: repeat(6, randomUserOfferEntry),
totalOffers: 6,
})
Expand All @@ -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,
Expand All @@ -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,
})
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Loading

0 comments on commit dc7c34d

Please sign in to comment.