Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

chore: show fullAppData if available #550

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@apollo/client": "^3.1.5",
"@cowprotocol/app-data": "v0.1.0",
"@cowprotocol/contracts": "1.3.1",
"@cowprotocol/cow-sdk": "^2.0.6",
"@cowprotocol/cow-sdk": "^2.2.1",
"@fortawesome/fontawesome-svg-core": "^6.1.2",
"@fortawesome/free-regular-svg-icons": "^6.1.2",
"@fortawesome/free-solid-svg-icons": "^6.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/api/operator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type RawOrder = EnrichedOrder
*/
export type Order = Pick<
RawOrder,
'owner' | 'uid' | 'appData' | 'kind' | 'partiallyFillable' | 'signature' | 'class'
'owner' | 'uid' | 'appData' | 'kind' | 'partiallyFillable' | 'signature' | 'class' | 'fullAppData'
> & {
receiver: string
txHash?: string
Expand Down
39 changes: 32 additions & 7 deletions src/components/AppData/DecodeAppData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,34 @@ import useSafeState from 'hooks/useSafeState'

type Props = {
appData: string
fullAppData?: string
showExpanded?: boolean
}

async function _getDecodedAppData(
appData: string,
fullAppData?: string,
): Promise<{ decodedAppData?: void | AnyAppDataDocVersion; isError: boolean }> {
// If the full appData is available, we try to parse it as JSON
if (fullAppData) {
try {
const decodedAppData = JSON.parse(fullAppData)
return { decodedAppData, isError: false }
} catch (error) {
console.error('Error parsing fullAppData from the API', { fullAppData }, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this branch also return isError: true ?

}
}

if (IPFS_INVALID_APP_IDS.includes(appData.toString())) {
return { isError: true }
}

const decodedAppData = await getDecodedAppData(appData.toString())
return { isError: false, decodedAppData }
}

const DecodeAppData = (props: Props): JSX.Element => {
const { appData, showExpanded = false } = props
const { appData, showExpanded = false, fullAppData } = props
const [appDataLoading, setAppDataLoading] = useSafeState(false)
const [appDataError, setAppDataError] = useSafeState(false)
const [decodedAppData, setDecodedAppData] = useSafeState<AnyAppDataDocVersion | void | undefined>(undefined)
Expand All @@ -41,14 +64,15 @@ const DecodeAppData = (props: Props): JSX.Element => {
setShowDecodedAppData(!showDecodedAppData)
}
if (decodedAppData) return
if (IPFS_INVALID_APP_IDS.includes(appData.toString())) {
setAppDataError(true)
return
}

setAppDataLoading(true)
try {
const decodedAppData = await getDecodedAppData(appData.toString())
setDecodedAppData(decodedAppData)
const { isError, decodedAppData } = await _getDecodedAppData(appData, fullAppData)
if (isError) {
setAppDataError(true)
} else {
setDecodedAppData(decodedAppData)
}
} catch (e) {
setDecodedAppData(undefined)
setAppDataError(true)
Expand All @@ -58,6 +82,7 @@ const DecodeAppData = (props: Props): JSX.Element => {
},
[
appData,
fullAppData,
decodedAppData,
setAppDataError,
setAppDataLoading,
Expand Down
3 changes: 2 additions & 1 deletion src/components/orders/DetailsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export function DetailsTable(props: Props): JSX.Element | null {
buyToken,
sellToken,
appData,
fullAppData,
} = order

if (!buyToken || !sellToken) {
Expand Down Expand Up @@ -385,7 +386,7 @@ export function DetailsTable(props: Props): JSX.Element | null {
<HelpTooltip tooltip={tooltip.appData} /> AppData
</td>
<td>
<DecodeAppData appData={appData} />
<DecodeAppData appData={appData} fullAppData={fullAppData ?? undefined} />
</td>
</tr>
</>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1377,10 +1377,10 @@
resolved "https://registry.yarnpkg.com/@cowprotocol/contracts/-/contracts-1.4.0.tgz#e93e5f25aac76feeaa348fa57231903274676247"
integrity sha512-XLs3SlPmXD4lbiWIO7mxxuCn1eE5isuO6EUlE1cj17HqN/wukDAN0xXYPx6umOH/XdjGS33miMiPHELEyY9siw==

"@cowprotocol/cow-sdk@^2.0.6":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@cowprotocol/cow-sdk/-/cow-sdk-2.1.0.tgz#b66adf0c4f6d9e6690762a1c3e169db5ba8feff1"
integrity sha512-/2bM58kddP1um9COO5XNPl88gOmnzAPr8fK6EGsdPkPuAQZtCfOWGvqajTtM+shixA21ZaATcSnNL57s5Zd8qw==
"@cowprotocol/cow-sdk@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@cowprotocol/cow-sdk/-/cow-sdk-2.2.1.tgz#496c7caf3a17e8873e8e4bb4cdbd54b2f966ac1e"
integrity sha512-EjvVnfHsM9a/f60msa2MebDQTF7137cIMr/fuCb4K0AdUAsk5NqTrr6fVrp+YMyVrIj9OZ/zhaJUxDfGcwza3w==
dependencies:
"@cowprotocol/contracts" "^1.4.0"
"@ethersproject/abstract-signer" "^5.7.0"
Expand Down