Skip to content

Commit

Permalink
Merge branch 'main' into bug/1022-download-full-board-instead-downloa…
Browse files Browse the repository at this point in the history
…ds-multiple-copies-of-the-first-page
  • Loading branch information
marc-aurele-besner authored Dec 18, 2024
2 parents 54af561 + 6d997c9 commit 8f9cbbf
Show file tree
Hide file tree
Showing 19 changed files with 2,758 additions and 1,907 deletions.
687 changes: 598 additions & 89 deletions explorer/gql/graphql.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Row = TransfersByAccountIdQuery['consensus_transfers'][0]
export const AccountTransfersList: FC<Props> = ({ accountId }) => {
const { ref, inView } = useInView()
const [sorting, setSorting] = useState<SortingState>([
{ id: TransferColumn.CreatedAt, desc: true },
{ id: TransferColumn.BlockHeight, desc: true },
])
const [pagination, setPagination] = useState({
pageSize: PAGE_SIZE,
Expand Down Expand Up @@ -121,17 +121,17 @@ export const AccountTransfersList: FC<Props> = ({ accountId }) => {
header: 'Block',
enableSorting: true,
cell: ({ row }: Cell<Row>) => (
<div key={`created_at-${row.original.id}`} className='row flex items-center gap-3'>
<div key={`block_height-${row.original.id}`} className='row flex items-center gap-3'>
<Link
data-testid={`transfer-created_at-${row.index}`}
data-testid={`transfer-block_height-${row.index}`}
href={INTERNAL_ROUTES.blocks.id.page(
network,
Routes.consensus,
row.original.created_at,
row.original.block_height,
)}
className='hover:text-primaryAccent'
>
<div>{row.original.created_at}</div>
<div>{row.original.block_height}</div>
</Link>
</div>
),
Expand Down Expand Up @@ -236,7 +236,7 @@ export const AccountTransfersList: FC<Props> = ({ accountId }) => {
enableSorting: true,
cell: ({ row }: Cell<Row>) => (
<div key={`${row.original.id}-created_at-${row.index}`}>
{row.original.timestamp(row.original.date)}
{row.original.timestamp(row.original.timestamp)}
</div>
),
},
Expand Down
8 changes: 4 additions & 4 deletions explorer/src/components/Consensus/Account/BalanceHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { formatUnits } from 'ethers'
import {
BalanceHistoryByAccountIdQuery,
BalanceHistoryByAccountIdQueryVariables,
Consensus_Account_Histories_Select_Column as BalanceHistoryColumn,
Consensus_Account_Histories_Bool_Exp as BalanceHistoryWhere,
Order_By as OrderBy,
Consensus_Transfers_Select_Column as TransferColumn,
Consensus_Transfers_Bool_Exp as TransferWhere,
} from 'gql/graphql'
import useIndexers from 'hooks/useIndexers'
import { useIndexersQuery } from 'hooks/useIndexersQuery'
Expand All @@ -37,7 +37,7 @@ type Row = BalanceHistoryByAccountIdQuery['consensus_account_histories'][0]
export const BalanceHistory: FC<Props> = ({ accountId }) => {
const { ref, inView } = useInView()
const [sorting, setSorting] = useState<SortingState>([
{ id: TransferColumn.CreatedAt, desc: true },
{ id: BalanceHistoryColumn.CreatedAt, desc: true },
])
const [pagination, setPagination] = useState({
pageSize: PAGE_SIZE,
Expand All @@ -57,7 +57,7 @@ export const BalanceHistory: FC<Props> = ({ accountId }) => {
[sorting],
)

const where: TransferWhere = useMemo(() => ({ id: { _eq: accountId } }), [accountId])
const where: BalanceHistoryWhere = useMemo(() => ({ id: { _eq: accountId } }), [accountId])

const variables = useMemo(() => {
return {
Expand Down
7 changes: 1 addition & 6 deletions explorer/src/components/Consensus/Account/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const QUERY_LAST_WEEK_REWARDS = gql`
) {
id
block_height
index_in_block
reward_type
amount
timestamp
Expand Down Expand Up @@ -97,7 +96,6 @@ export const QUERY_REWARDS_LIST = gql`
) {
id
block_height
index_in_block
reward_type
amount
timestamp
Expand Down Expand Up @@ -164,8 +162,7 @@ export const QUERY_ACCOUNT_TRANSFERS = gql`
fee
success
timestamp
date
created_at
block_height
}
}
`
Expand All @@ -189,7 +186,6 @@ export const QUERY_ACCOUNT_BALANCE_HISTORY = gql`
nonce
free
created_at
updated_at
_block_range
}
}
Expand All @@ -200,7 +196,6 @@ export const QUERY_ALL_REWARDS_FOR_ACCOUNT_BY_ID = gql`
consensus_rewards(where: { account_id: { _eq: $accountId }, amount: { _gt: 0 } }, limit: 1) {
id
block_height
index_in_block
reward_type
amount
timestamp
Expand Down
17 changes: 16 additions & 1 deletion explorer/src/components/Storage/Files/FilePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LockClosedIcon } from '@heroicons/react/24/outline'
import { Arguments } from 'components/common/Arguments'
import { Spinner } from 'components/common/Spinner'
import { GetCidQuery, GetCidQueryVariables } from 'gql/graphql'
Expand All @@ -16,6 +17,9 @@ type Props = {
type PreviewData = {
type: string
data: ArrayBuffer
isEncrypted: boolean
// eslint-disable-next-line @typescript-eslint/no-explicit-any
uploadOptions: any
}

export const FilePreview: FC<Props> = ({ cid }) => {
Expand All @@ -31,11 +35,13 @@ export const FilePreview: FC<Props> = ({ cid }) => {

const fetchData = useCallback(async () => {
if (data) {
const { dataArrayBuffer } = extractFileData(data)
const { dataArrayBuffer, isEncrypted, uploadOptions } = extractFileData(data)
const fileType = await detectFileType(dataArrayBuffer)
setRawData({
type: fileType,
data: dataArrayBuffer,
isEncrypted,
uploadOptions,
})
}
}, [data])
Expand All @@ -60,6 +66,15 @@ export const FilePreview: FC<Props> = ({ cid }) => {
if (!imageSrc) return <></>

switch (true) {
case rawData?.isEncrypted:
return (
<div className='flex items-center'>
<LockClosedIcon className={'ml-2 size-6 shrink-0'} stroke='#DE67E4' />
<p className='text-sm font-medium text-grayDarker dark:text-white md:text-xl'>
No preview available for encrypted files
</p>
</div>
)
case rawData?.type.startsWith('image'):
return (
<Image
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/constants/indexers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Indexer {
telemetryNetworkName?: string
}

const LOCAL_INDEXER = 'https://subql.green.mainnet.subspace.network/v1/graphql'
const LOCAL_INDEXER = 'https://subql.blue.mainnet.subspace.network/v1/graphql'

export const indexers: Indexer[] = [
{
Expand Down
36 changes: 23 additions & 13 deletions explorer/src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ const extractFileDataByType = (data: any, type: 'file' | 'folder' | 'metadata')
let rawData: string = ''
let dataArrayBuffer: ArrayBuffer = new ArrayBuffer(0)
let depth = 0
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let uploadOptions: any

try {
if (data['files_' + type + 's'][0].chunk?.uploadOptions) {
uploadOptions = JSON.parse(data['files_' + type + 's'][0].chunk?.uploadOptions)
if (uploadOptions.encryption.algorithm)
return { rawData, dataArrayBuffer, isEncrypted: true, uploadOptions }
}
} catch (error) {
console.error('Error checking uploadOptions:', error)
}

if (data['files_' + type + 's'][0][type + '_cids'].length === 0) {
rawData = data['files_' + type + 's'][0].chunk?.data ?? ''
dataArrayBuffer = Object.values(JSON.parse(rawData)) as unknown as ArrayBuffer
Expand All @@ -92,23 +105,20 @@ const extractFileDataByType = (data: any, type: 'file' | 'folder' | 'metadata')
}
}
try {
if (data['files_' + type + 's'][0].chunk?.uploadOptions) {
const options = JSON.parse(data['files_' + type + 's'][0].chunk?.uploadOptions)
if (options.compression.algorithm === 'ZLIB') {
const inflate = new Zlib.Inflate(new Uint8Array(dataArrayBuffer), {
index: 0,
bufferSize: 1024,
bufferType: Zlib.Inflate.BufferType.BLOCK,
resize: true,
verify: true,
})
dataArrayBuffer = inflate.decompress()
}
if (uploadOptions.compression.algorithm === 'ZLIB') {
const inflate = new Zlib.Inflate(new Uint8Array(dataArrayBuffer), {
index: 0,
bufferSize: 1024,
bufferType: Zlib.Inflate.BufferType.BLOCK,
resize: true,
verify: true,
})
dataArrayBuffer = inflate.decompress()
}
} catch (error) {
console.error('Error decompressing data:', error)
}
return { rawData, dataArrayBuffer }
return { rawData, dataArrayBuffer, isEncrypted: false, uploadOptions }
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Loading

0 comments on commit 8f9cbbf

Please sign in to comment.