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

Commit 12a9e3e

Browse files
committed
feat(app-data): upgrade to latest appData version 1.1.0 (#651)
* feat(app-data): upgrade to latest appData version 1.1.0 * chore: show appData array buttons * chore: comment out ipfs stuff * refactor: remove stuff that's not needed and remove some `any`s * refactor: sort imports * chore: remove IPFS reference * refactor: format
1 parent 85d63dd commit 12a9e3e

File tree

5 files changed

+64
-89
lines changed

5 files changed

+64
-89
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"author": "",
4747
"dependencies": {
4848
"@apollo/client": "^3.1.5",
49-
"@cowprotocol/app-data": "^1.0.2",
49+
"@cowprotocol/app-data": "^1.1.0",
5050
"@cowprotocol/contracts": "1.3.1",
5151
"@cowprotocol/cow-sdk": "^2.2.1",
5252
"@fortawesome/fontawesome-svg-core": "^6.1.2",

src/apps/explorer/pages/AppData/EncodePage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { RowWithCopyButton } from 'components/common/RowWithCopyButton'
88
import AppDataWrapper from 'components/common/AppDataWrapper'
99

1010
import {
11-
INITIAL_FORM_VALUES,
11+
CustomField,
12+
FormProps,
1213
getSchema,
13-
transformErrors,
1414
handleErrors,
15+
INITIAL_FORM_VALUES,
16+
transformErrors,
1517
uiSchema,
16-
CustomField,
17-
FormProps,
1818
} from './config'
1919
import { TabData } from '.'
2020
import { metadataApiSDK } from 'cowSdk'
@@ -201,7 +201,7 @@ const EncodePage: React.FC<EncodeProps> = ({ tabData, setTabData /* handleTabCha
201201
orders. This is useful for giving context to your orders, like crediting the order to a specific UI, adding
202202
affiliate information, or even signalling your order should be treated in a special way.
203203
</p>
204-
<p>This field is the hexadecimal digest of an IPFS document’s CID of a JSON file.</p>
204+
<p>This field is the hexadecimal digest of a JSON file.</p>
205205
<p>
206206
The JSON file follows a
207207
<a target="_blank" href="https://json-schema.org" rel="noreferrer">
@@ -402,7 +402,7 @@ const EncodePage: React.FC<EncodeProps> = ({ tabData, setTabData /* handleTabCha
402402
{error && !isDocUploaded && (
403403
<Notification type="error" message={error} closable={false} appendMessage={false} />
404404
)}
405-
</div>
405+
</div>
406406
*/}
407407
</>
408408
)

src/apps/explorer/pages/AppData/config.tsx

Lines changed: 34 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,21 @@ export const INITIAL_FORM_VALUES = {
1717
metadata: {},
1818
}
1919

20-
export const INVALID_IPFS_CREDENTIALS = [
21-
'Type error',
22-
"Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.",
23-
]
20+
// export const INVALID_IPFS_CREDENTIALS = [
21+
// 'Type error',
22+
// "Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.",
23+
// ]
2424

2525
export type FormProps = Record<string, any>
2626

2727
export const getSchema = async (): Promise<JSONSchema7> => {
2828
const latestSchema = (await metadataApiSDK.getAppDataSchema(LATEST_APP_DATA_VERSION)) as JSONSchema7
29-
deleteAllPropertiesByName(latestSchema, 'examples')
30-
deleteAllPropertiesByName(latestSchema, '$id')
31-
return formatSchema(latestSchema)
32-
}
33-
34-
const formatSchema = (schema: JSONSchema7): JSONSchema7 => {
35-
const formattedSchema = structuredClone(schema)
3629

37-
return formattedSchema
30+
return makeSchemaCopy(latestSchema)
3831
}
3932

33+
const makeSchemaCopy = (schema: JSONSchema7): JSONSchema7 => structuredClone(schema)
34+
4035
export const transformErrors = (errors: AjvError[]): AjvError[] => {
4136
return errors.reduce((errorsList, error) => {
4237
if (error.name === 'required') {
@@ -67,65 +62,26 @@ export const handleErrors = (
6762
): FormValidation => {
6863
if (!ref.current) return errors
6964
const { errors: formErrors } = ref.current?.state as FormProps
70-
handler(formErrors.length > 0)
65+
handler(Array.isArray(formErrors) && formErrors?.length > 0)
7166
return errors
7267
}
7368

74-
const deleteAllPropertiesByName = (schema: JSONSchema7, property: string): void => {
75-
if (schema[property]) {
76-
deletePropertyPath(schema, property)
77-
}
78-
if (!schema.properties) return
79-
80-
for (const field in schema.properties) {
81-
deleteAllPropertiesByName(schema.properties[field] as JSONSchema7, property)
82-
}
83-
}
84-
85-
export const deletePropertyPath = (obj: any, path: any): void => {
86-
if (!obj || !path) {
87-
return
88-
}
89-
90-
if (typeof path === 'string') {
91-
path = path.split('.')
92-
}
93-
94-
for (let i = 0; i < path.length - 1; i++) {
95-
obj = obj[path[i]]
96-
97-
if (typeof obj === 'undefined') {
98-
return
99-
}
100-
}
101-
102-
const propName = path.pop()
103-
if (!propName) {
104-
return
105-
}
106-
107-
const propConfigurable = Object.getOwnPropertyDescriptor(obj, propName)?.configurable || false
108-
if (propConfigurable) {
109-
delete obj[propName]
110-
}
111-
}
112-
113-
export const ipfsSchema: JSONSchema7 = {
114-
type: 'object',
115-
required: ['pinataApiKey', 'pinataApiSecret'],
116-
properties: {
117-
pinataApiKey: {
118-
type: 'string',
119-
title: 'Pinata API key',
120-
description: 'Add your Pinata API key.',
121-
},
122-
pinataApiSecret: {
123-
type: 'string',
124-
title: 'Pinata API secret',
125-
description: 'Add your Pinata API secret.',
126-
},
127-
},
128-
}
69+
// export const ipfsSchema: JSONSchema7 = {
70+
// type: 'object',
71+
// required: ['pinataApiKey', 'pinataApiSecret'],
72+
// properties: {
73+
// pinataApiKey: {
74+
// type: 'string',
75+
// title: 'Pinata API key',
76+
// description: 'Add your Pinata API key.',
77+
// },
78+
// pinataApiSecret: {
79+
// type: 'string',
80+
// title: 'Pinata API secret',
81+
// description: 'Add your Pinata API secret.',
82+
// },
83+
// },
84+
// }
12985

13086
export const decodeAppDataSchema: JSONSchema7 = {
13187
type: 'object',
@@ -197,13 +153,13 @@ export const uiSchema = {
197153
},
198154
}
199155

200-
export const ipfsUiSchema = {
201-
pinataApiKey: {
202-
'ui:field': 'cField',
203-
tooltip: 'Add your Pinata API key.',
204-
},
205-
pinataApiSecret: {
206-
'ui:field': 'cField',
207-
tooltip: 'Add your Pinata API secret key.',
208-
},
209-
}
156+
// export const ipfsUiSchema = {
157+
// pinataApiKey: {
158+
// 'ui:field': 'cField',
159+
// tooltip: 'Add your Pinata API key.',
160+
// },
161+
// pinataApiSecret: {
162+
// 'ui:field': 'cField',
163+
// tooltip: 'Add your Pinata API secret key.',
164+
// },
165+
// }

src/apps/explorer/pages/AppData/styled.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ export const Wrapper = styled(WrapperTemplate)`
119119
line-height: 1.6rem;
120120
}
121121
122+
i.glyphicon {
123+
display: none;
124+
}
125+
.btn-add::after {
126+
content: 'Add';
127+
}
128+
.array-item-copy::after {
129+
content: 'Copy';
130+
}
131+
.array-item-move-up::after {
132+
content: 'Move Up';
133+
}
134+
.array-item-move-down::after {
135+
content: 'Move Down';
136+
}
137+
.array-item-remove::after {
138+
content: 'Remove';
139+
}
140+
122141
.hidden-content {
123142
${media.desktop} {
124143
position: sticky;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,10 @@
13591359
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
13601360
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==
13611361

1362-
"@cowprotocol/app-data@^1.0.2":
1363-
version "1.0.2"
1364-
resolved "https://registry.yarnpkg.com/@cowprotocol/app-data/-/app-data-1.0.2.tgz#e559ed892265b84d926a5c84ce6add14e597bb57"
1365-
integrity sha512-tf4KGK+moHEAjgmOQ8E7MaRHM/rscbzFxsLE/Q+bLXNYcrcwmFDn/VjahkO7bMWhDQj4whmdgw8rbHlPo7zjdw==
1362+
"@cowprotocol/app-data@^1.1.0":
1363+
version "1.1.0"
1364+
resolved "https://registry.yarnpkg.com/@cowprotocol/app-data/-/app-data-1.1.0.tgz#38d91a79388220bc1ff99d2b6d0d3e3cce38e8f9"
1365+
integrity sha512-r55wyVrVnyq32KcswGN+1q5jTIfkLq4NlhibLWpe8px05lqvHA/RXRLO8lTkK7WFtlbO4iSnQqkIs4wqLc80kg==
13661366
dependencies:
13671367
ajv "^8.11.0"
13681368
cross-fetch "^3.1.5"

0 commit comments

Comments
 (0)