Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default tseslint.config(
// Ensure Next.js link, image, and other best practices
...eslintPluginReactHooks.configs.recommended.rules,
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'no-prototype-builtins': 'off',
'require-jsdoc': 'off',
Expand Down
2 changes: 1 addition & 1 deletion src/api/assets/getDexAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { osmosisTokens } from 'data/assets/osmosis-tokens'

export default async function getDexAssets(chainConfig: ChainConfig) {
try {
let tokens: any[]
let tokens: AstroportAsset[]

// Load essential static data based on chain ID
switch (chainConfig.id) {
Expand Down
14 changes: 7 additions & 7 deletions src/app/api/og/perps/[market]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { neutronPerps } from '../../../../../data/assets/neutron-perps'
// Use Node.js runtime to avoid disabling SSG for other pages
export const runtime = 'nodejs'

export async function GET(request: Request, context: any) {
export async function GET(request: Request, context: { params: Promise<{ market: string }> }) {
try {
const marketParam = context.params.market
const marketDenom = `perps/${decodeURIComponent(
Array.isArray(marketParam) ? marketParam[0] : marketParam,
)}`
const params = await context.params
const marketParam = params.market
const marketDenom = `perps/${decodeURIComponent(marketParam)}`

// Find the market asset data
const marketAsset = neutronPerps.find((asset) => asset.denom === marketDenom)
Expand Down Expand Up @@ -75,8 +74,9 @@ export async function GET(request: Request, context: any) {
height: 540,
},
)
} catch (e: any) {
console.log(`${e.message}`)
} catch (e: unknown) {
const message = e instanceof Error ? e.message : 'Unknown error'
console.log(message)
return new Response(`Failed to generate the image`, {
status: 500,
})
Expand Down
26 changes: 18 additions & 8 deletions src/components/common/Chart/PieChart/PieChartBody.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cell, Legend, Pie, PieChart, ResponsiveContainer } from 'recharts'
import { Cell, Legend, Pie, PieChart, PieLabelRenderProps, ResponsiveContainer } from 'recharts'

interface PieChartData {
name: string
Expand All @@ -14,24 +14,34 @@ interface Props {

const RADIAN = Math.PI / 180

const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent }: any) => {
const radius = innerRadius + (outerRadius - innerRadius) * 0.5
const x = cx + radius * Math.cos(-midAngle * RADIAN)
const y = cy + radius * Math.sin(-midAngle * RADIAN)
const renderCustomizedLabel = (props: PieLabelRenderProps) => {
const { cx, cy, midAngle, innerRadius, outerRadius, percent } = props

if (percent < 0.05) return null // Don't show label if slice is too small
// Type guards for numeric properties
const cxNum = typeof cx === 'number' ? cx : 0
const cyNum = typeof cy === 'number' ? cy : 0
const midAngleNum = typeof midAngle === 'number' ? midAngle : 0
const innerRadiusNum = typeof innerRadius === 'number' ? innerRadius : 0
const outerRadiusNum = typeof outerRadius === 'number' ? outerRadius : 0
const percentNum = typeof percent === 'number' ? percent : 0

const radius = innerRadiusNum + (outerRadiusNum - innerRadiusNum) * 0.5
const x = cxNum + radius * Math.cos(-midAngleNum * RADIAN)
const y = cyNum + radius * Math.sin(-midAngleNum * RADIAN)

if (percentNum < 0.05) return null // Don't show label if slice is too small

return (
<text
x={x}
y={y}
fill='white'
textAnchor={x > cx ? 'start' : 'end'}
textAnchor={x > cxNum ? 'start' : 'end'}
dominantBaseline='central'
fontSize={12}
fontWeight={600}
>
{`${(percent * 100).toFixed(1)}%`}
{`${(percentNum * 100).toFixed(1)}%`}
</text>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/Chart/common/Legend/ChartLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ interface LegendEntry {
legendType: string
name: string
dataKey: string
[key: string]: any
[key: string]: unknown
}
}

interface Props {
payload: LegendEntry[]
data?: any[]
data?: Record<string, unknown>[]
}

export default function ChartLegend(props: Props) {
Expand Down
35 changes: 30 additions & 5 deletions src/components/common/Table/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,35 @@ function getBorderColor(
return perpRow.tradeDirection === 'short' ? 'border-loss' : 'border-profit'
}

// Type guards for row data
function hasName(row: unknown): row is { name: string } {
return typeof row === 'object' && row !== null && 'name' in row
}

function hasIsWhitelisted(row: unknown): row is { isWhitelisted?: boolean } {
return typeof row === 'object' && row !== null
}

function hasAssetDenom(row: unknown): row is { asset: { denom: string } } {
return (
typeof row === 'object' &&
row !== null &&
'asset' in row &&
typeof row.asset === 'object' &&
row.asset !== null &&
'denom' in row.asset
)
}

export default function Row<T>(props: Props<T>) {
const { renderExpanded, table, row, type, spacingClassName, isSelectable, isBalancesTable } =
props
const canExpand = !!renderExpanded

const name = (row.original as any).name ?? ''
const name = hasName(row.original) ? row.original.name : ''
const isWhitelisted =
(row.original as any).isWhitelisted !== false && !name.includes('Perps USDC Vault')
(hasIsWhitelisted(row.original) ? row.original.isWhitelisted !== false : true) &&
!name.includes('Perps USDC Vault')

return (
<>
Expand All @@ -65,8 +86,8 @@ export default function Row<T>(props: Props<T>) {
!isExpanded && row.toggleExpanded()
}

if (props.onClick) {
props.onClick((row.original as any).asset.denom)
if (props.onClick && hasAssetDenom(row.original)) {
props.onClick(row.original.asset.denom)
}
}}
>
Expand All @@ -83,7 +104,11 @@ export default function Row<T>(props: Props<T>) {
'border-l',
type &&
type !== 'strategies' &&
getBorderColor(type, cell.row.original as any, isWhitelisted),
getBorderColor(
type,
cell.row.original as AccountBalanceRow | AccountStrategyRow | AccountPerpRow,
isWhitelisted,
),
cell.column.columnDef.meta?.className,
!isWhitelisted && isBalancesTable && 'opacity-60',
!isWhitelisted && isBalancesTable && 'group-hover/assetRow:opacity-100',
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/charts/useChartDataTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ChartTransformation {
}

export const useChartDataTransform = (
data: PerpsGlobalData | PerpsMarketData | PerpsVaultApyData,
data: PerpsGlobalData | PerpsMarketData | PerpsVaultApyData | OverviewData | null | undefined,
transformations: ChartTransformation[],
) => {
return useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/tokenomics/useOverviewChartData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OVERVIEW_CHART_TRANSFORMATIONS } from 'constants/chartData'
import { useChartDataTransform } from 'hooks/charts/useChartDataTransform'

export const useOverviewChartData = (data: any) => {
export const useOverviewChartData = (data: OverviewData | null | undefined) => {
const tvlData = useChartDataTransform(data, OVERVIEW_CHART_TRANSFORMATIONS.tvl)
const supplyBorrowData = useChartDataTransform(data, OVERVIEW_CHART_TRANSFORMATIONS.supplyBorrow)

Expand Down
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { devtools } from 'zustand/middleware'
import createCommonSlice from 'store/slices/common'
import createModalSlice from 'store/slices/modal'

const store = (set: StoreApi<Store>['setState'], get: StoreApi<Store>['getState']) => ({
const store = (set: StoreApi<Store>['setState'], get: StoreApi<Store>['getState']): Store => ({
...createCommonSlice(set, get),
...createModalSlice(set, get),
})
Expand Down
2 changes: 1 addition & 1 deletion src/store/slices/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StoreApi } from 'zustand'
export default function createCommonSlice(
set: StoreApi<Store>['setState'],
get: StoreApi<Store>['getState'],
) {
): CommonSlice {
return {
accounts: null,
balances: [],
Expand Down
2 changes: 1 addition & 1 deletion src/store/slices/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StoreApi } from 'zustand'
export default function createModalSlice(
set: StoreApi<Store>['setState'],
get: StoreApi<Store>['getState'],
) {
): ModalSlice {
return {
resetStettingsModal: false,
settingsModal: false,
Expand Down
6 changes: 5 additions & 1 deletion src/types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,11 @@ interface TransactionEventAttribute {
type TransactionType = 'default' | 'oracle' | 'create' | 'burn' | 'unlock' | 'transaction'

interface CommonSlice {
accounts?: Account[] | null
address?: string
chainConfig: ChainConfig
creditAccounts?: Account[] | null
hlsAccounts?: HLSAccountWithStrategy[] | null
userDomain?: {
domain: string
domain_full: string
Expand Down Expand Up @@ -1103,6 +1106,7 @@ interface FocusComponent {
}

interface ModalSlice {
resetStettingsModal: boolean
settingsModal: boolean
}

Expand Down Expand Up @@ -1314,7 +1318,7 @@ interface AstroportAsset {
chainId: string
denom: string
symbol: string
icon?: string
icon?: string | null
description: string
decimals: number
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/classes/BNCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class BNCoin {
}
}

toSignedCoin(): any {
toSignedCoin(): { denom: string; size: string } {
return {
denom: this.denom,
size: this.amount.integerValue().toString(),
Expand Down
18 changes: 15 additions & 3 deletions src/utils/array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export const byDenom = (denom: string) => (entity: any) => entity.denom === denom
export const bySymbol = (symbol: string) => (entity: any) => entity.symbol === symbol
const byTokenDenom = (denom: string) => (entity: any) => entity.token.denom === denom
interface HasDenom {
denom: string
}

interface HasSymbol {
symbol: string
}

interface HasToken {
token: { denom: string }
}

export const byDenom = (denom: string) => (entity: HasDenom) => entity.denom === denom
export const bySymbol = (symbol: string) => (entity: HasSymbol) => entity.symbol === symbol
const byTokenDenom = (denom: string) => (entity: HasToken) => entity.token.denom === denom

function partition<T>(arr: Array<T>, predicate: (val: T) => boolean): [Array<T>, Array<T>] {
const partitioned: [Array<T>, Array<T>] = [[], []]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getApproximateHourlyInterest(amount: string, borrowRate: number) {
.multipliedBy(amount)
}

function asyncThrottle<F extends (...args: any[]) => Promise<any>>(func: F, wait?: number) {
function asyncThrottle<F extends (...args: never[]) => Promise<unknown>>(func: F, wait?: number) {
const throttled = throttle((resolve, reject, args: Parameters<F>) => {
func(...args)
.then(resolve)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Middleware, SWRHook } from 'swr'

export const debugSWR: Middleware = (useSWRNext: SWRHook) => (key, fetcher, config) => {
const extendedFetcher = async (...args: any[]) => {
const extendedFetcher = async (...args: unknown[]) => {
const startTime = Date.now()
const res = await fetcher!(...args)
process.env.NODE_ENV !== 'production' &&
Expand Down
26 changes: 13 additions & 13 deletions src/utils/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,53 +104,53 @@ function resolvePerpsPositions(
type: 'market',
denom: position.denom,
baseDenom: position.base_denom,
amount: BN(position.size as any), // Amount is negative for SHORT positions
tradeDirection: BN(position.size as any).isNegative() ? 'short' : 'long',
amount: BN(position.size as unknown as string), // Amount is negative for SHORT positions
tradeDirection: BN(position.size as unknown as string).isNegative() ? 'short' : 'long',
entryPrice: BN(position.entry_exec_price),
currentPrice: BN(position.current_exec_price),
pnl: {
net: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.unrealized_pnl.pnl as any)
BN(position.unrealized_pnl.pnl as unknown as string)
.div(basePrice)
.plus(position.realized_pnl.pnl as any),
.plus(position.realized_pnl.pnl as unknown as string),
),
realized: {
net: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.realized_pnl.pnl as any),
BN(position.realized_pnl.pnl as unknown as string),
),
price: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.realized_pnl.price_pnl as any),
BN(position.realized_pnl.price_pnl as unknown as string),
),
funding: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.realized_pnl.accrued_funding as any),
BN(position.realized_pnl.accrued_funding as unknown as string),
),
fees: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.realized_pnl.closing_fee as any).plus(
position.realized_pnl.opening_fee as any,
BN(position.realized_pnl.closing_fee as unknown as string).plus(
position.realized_pnl.opening_fee as unknown as string,
),
),
},
unrealized: {
net: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.unrealized_pnl.pnl as any),
BN(position.unrealized_pnl.pnl as unknown as string),
),
price: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.unrealized_pnl.price_pnl as any),
BN(position.unrealized_pnl.price_pnl as unknown as string),
),
funding: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.unrealized_pnl.accrued_funding as any),
BN(position.unrealized_pnl.accrued_funding as unknown as string),
),
fees: BNCoin.fromDenomAndBigNumber(
position.base_denom,
BN(position.unrealized_pnl.closing_fee as any),
BN(position.unrealized_pnl.closing_fee as unknown as string),
),
},
},
Expand Down
Loading