Skip to content

Commit

Permalink
refactor: remove deprecated transformResource api function
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Oct 3, 2024
1 parent a79f82a commit a9ae2a1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 300 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { callApi, getTransactionDetailsNew } from '@api/_deprecated/gateway'
import type { LayoutLoad } from './$types'
import { transformResource } from '@api/_deprecated/utils/entities/resource'
import { transformResource } from '@api/utils/entities/resource'
import { ResultAsync } from 'neverthrow'
import type { ComponentProps } from 'svelte'
import type Summary from '@dashboard-pages/search-pages/transaction/summary/Summary.svelte'
Expand All @@ -13,34 +13,6 @@ import { getNftData } from '@api/_deprecated/utils/nft-data'
import { pipe } from 'ramda'
import { handleGatewayResult } from '../../../../utils'

import type { EntityType } from '@common/ret'
import { http } from '@common/http'

const ERROR_MSG = 'Failed to load transaction data.'

const getEntityTypes = async (
addresses: string[]
): Promise<{ [address: string]: EntityType }> =>
http.post('/api/ret/entity-type', {
addresses
})

const getEntityDetails = (stateVersion?: number) => (addresses: string[]) =>
pipe(
() =>
callApi(
'getEntityDetailsVaultAggregated',
addresses,
undefined,
stateVersion
? {
state_version: stateVersion
}
: undefined
),
handleGatewayResult((_) => ERROR_MSG)
)()

export const load: LayoutLoad = ({ params, data }) => {
const details = getTransactionDetailsNew(params.transaction).unwrapOr(
undefined
Expand Down Expand Up @@ -71,7 +43,9 @@ export const load: LayoutLoad = ({ params, data }) => {
: undefined

return entities
? callApi('getEntityDetailsVaultAggregated', entities)
? callApi('getEntityDetailsVaultAggregated', entities, {
nativeResourceDetails: true
})
: undefined
})

Expand All @@ -81,15 +55,13 @@ export const load: LayoutLoad = ({ params, data }) => {

if (entitiesResult.isErr()) throw entitiesResult.error

const resources = await Promise.all(
entitiesResult.value.map((resource) =>
transformResource(resource, getEntityTypes, getEntityDetails())
)
const resources = entitiesResult.value.map((resource) =>
transformResource(resource)
)

const resourceInfo = resources.map((resource) => ({
resource,
icon: resource.metadata.standard.icon_url?.value,
icon: resource.metadata.expected.icon_url?.typed.value,
name: resource.displayName,
address: resource.address
}))
Expand Down Expand Up @@ -149,7 +121,7 @@ export const load: LayoutLoad = ({ params, data }) => {
change: change.change.balance_change,
token: {
address: change.change.resource_address,
icon: icon?.href,
icon: icon,
name
}
})
Expand Down Expand Up @@ -195,7 +167,7 @@ export const load: LayoutLoad = ({ params, data }) => {
change: change.change.balance_change,
token: {
address: change.change.resource_address,
icon: icon?.href || '',
icon: icon || '',
name: 'Radix (XRD)'
}
})
Expand Down
3 changes: 0 additions & 3 deletions packages/ui/src/api/_deprecated/utils/entities/account.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/ui/src/api/_deprecated/utils/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type KnownStandardTypes,
type MetadataTypeToNativeType
} from '../metadata'
import type { PoolUnit } from './pool-unit'
import type { Resource } from './resource'
import type { Validator } from './validator'
import type {
Expand All @@ -13,7 +12,7 @@ import type {
StateEntityDetailsVaultResponseItem
} from '@common/gateway-sdk'

export type Entity = Validator | Resource | PoolUnit
export type Entity = Validator | Resource

export type _Entity<
Type extends string,
Expand Down
152 changes: 0 additions & 152 deletions packages/ui/src/api/_deprecated/utils/entities/pool-unit.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/ui/src/api/_deprecated/utils/entities/resource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
callApi,
getEntityDetails,
getSingleEntityDetails
} from '@api/_deprecated/gateway'
Expand All @@ -19,12 +18,6 @@ import { BigNumber } from 'bignumber.js'
import { getNonFungibleData } from '@api/_deprecated/gateway'
import { transformEntity, type _Entity } from '.'
import { transformNft, type _NonFungible, type NonFungible } from '../nfts'
import {
getPoolUnits,
hasPoolMetadataSet,
type GetEntityTypesFn,
type GetEntityDetailsFn
} from './pool-unit'
import { type AuthInfo, isAllowed } from '../../../utils/auth'

type _Resource<T extends 'fungible' | 'non-fungible'> = _Entity<
Expand Down Expand Up @@ -466,26 +459,6 @@ export const transformFungible = async (
}))
}

export const transformResource = async (
entity: StateEntityDetailsVaultResponseItem,
getEntityTypesFn: GetEntityTypesFn,
getEntityDetailsFn: GetEntityDetailsFn
) => {
if (entity.details?.type === 'FungibleResource') {
const fungible = transformFungibleResource(entity)
if (hasPoolMetadataSet(fungible)) {
return getPoolUnits(
[fungible],
getEntityTypesFn,
getEntityDetailsFn
).then((res) => res[0] ?? fungible)
}
return fungible
}

return transformNonFungibleResource(entity)
}

export const transformResources =
(
stateOptions?: StateEntityDetailsOptions,
Expand Down
Loading

0 comments on commit a9ae2a1

Please sign in to comment.