Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4337 API Reference #477

Merged
merged 5 commits into from
May 17, 2024
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
51 changes: 21 additions & 30 deletions .github/scripts/generateApiReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,33 @@ const generateCategoryContent = category => `<Grid my={8} />

<Grid my={6} />

${category.paths
.filter(
path =>
path !== '/v1/safes/{address}/balances/' &&
path !== '/v1/safes/{address}/balances/usd/' &&
path !== '/v1/safes/{address}/transactions/' &&
path !== '/v1/transactions/{safe_tx_hash}/'
)
.map(path => generatePathContent(path))
.join('\n')}`

const getCategories = version =>
Object.keys(mainnetApiJson.paths)
.filter(path => path.includes(version))
.map(path => {
const pathname = path.replace('/' + version + '/', '').slice(0, -1)
return {
title: pathname.split('/')[0],
paths: Object.entries(mainnetApiJson.paths)
.filter(([key]) => key.includes(path))
.flat()
.filter((value, index) => index % 2 === 0)
}
})
.filter(
(category, index, self) =>
index === self.findIndex(t => t.title === category.title) &&
category.title !== ''
${category.paths.map(path => generatePathContent(path)).join('\n')}`

const getCategories = version => {
const allMethods = Object.entries(mainnetApiJson.paths)
.map(([k, v]) => Object.values(v))
.flat()
const allCategories = Array.from(
new Set(
allMethods
.map(method => method.tags)
.flat()
.filter(Boolean)
)
)
return allCategories.map(title => ({
title,
paths: allMethods
.filter(method => method.tags?.includes(title) && !method.deprecated)
.map(m => m.path)
}))
}

const generateMainContent = () => {
const categories = [...getCategories('v1')].filter(
c =>
c.title !== 'about' &&
c.title !== 'notifications' &&
c.title !== 'transactions'
c.title !== 'notifications'
)

return `import Path from './Path'
Expand Down
11 changes: 2 additions & 9 deletions components/ApiReference/Parameter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Property from './Property'
import Hr from '../Hr'
import { MdxHeading } from '../../lib/mdx'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -10,10 +9,7 @@ const Parameters: React.FC<{ parameters: any[] }> = ({ parameters }) => {
return (
<>
{query.length > 0 && (
<>
<MdxHeading headingLevel={4}>Query Parameters</MdxHeading>
<Hr />
</>
<MdxHeading headingLevel={4}>Query Parameters</MdxHeading>
)}
{query.map(parameter => (
<Property
Expand All @@ -26,10 +22,7 @@ const Parameters: React.FC<{ parameters: any[] }> = ({ parameters }) => {
/>
))}
{body.length > 0 && (
<>
<MdxHeading headingLevel={4}>Request Body</MdxHeading>
<Hr />
</>
<MdxHeading headingLevel={4}>Request Body</MdxHeading>
)}
{body.map(parameter =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
1 change: 0 additions & 1 deletion components/ApiReference/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ const Responses: React.FC<{ responses: any[] }> = ({ responses }) => {
return (
<Grid sx={{ mt: 2 }}>
<MdxHeading headingLevel={4}>Responses</MdxHeading>
<Hr />
{responses?.map?.((response, index) => (
<Response key={index} index={index} response={response} />
))}
Expand Down
4 changes: 3 additions & 1 deletion components/ApiReference/SampleRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SampleRequestHeader: React.FC<{
const [network] = useContext(NetworkContext)

return (
<Grid container justifyContent='space-between'>
<Grid container justifyContent='space-between' alignItems='center'>
<MdxHeading headingLevel={4}>Sample Request</MdxHeading>
<Button
variant='text'
Expand All @@ -20,6 +20,8 @@ const SampleRequestHeader: React.FC<{
target='_blank'
rel='noopener noreferrer'
sx={{
mt: 1,
height: '36px',
color: 'rgba(249,250,251,.7)',
backgroundColor: ({ palette }) => palette.grey[900]
}}
Expand Down
2 changes: 1 addition & 1 deletion components/ApiReference/examples/-v1-contracts--get.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"count": 138998,
"count": 143350,
"next": "https://safe-transaction-mainnet.safe.global/api/v1/contracts/?limit=2&offset=2",
"previous": null,
"results": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"tokenAddress": null,
"token": null,
"balance": "100000000000000"
},
{
"tokenAddress": "0x111111111117dC0aa78b770fA6A738034120C302",
"token": {
"name": "1INCH Token",
"symbol": "1INCH",
"decimals": 18,
"logoUri": "https://safe-transaction-assets.safe.global/tokens/logos/0x111111111117dC0aa78b770fA6A738034120C302.png"
},
"balance": "1000000000000000000"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"value": "0x0000000000000000000000000000000000000000"
}
]
}
},
"userOperation": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"count": 0,
"next": null,
"previous": null,
"results": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"count": 0,
"next": null,
"previous": null,
"results": []
}
14 changes: 7 additions & 7 deletions components/ApiReference/examples/-v1-tokens--get.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"count": 39652,
"count": 40276,
"next": "https://safe-transaction-mainnet.safe.global/api/v1/tokens/?limit=2&offset=2",
"previous": null,
"results": [
{
"type": "ERC20",
"address": "0x85A7a676D610A95865E842d2754b1fd335E55767",
"address": "0x56EBDaE96d179549f279ea0cFEa3b3432B8Cd2bC",
"name": "",
"symbol": "",
"decimals": 7,
"logoUri": "https://safe-transaction-assets.safe.global/tokens/logos/0x85A7a676D610A95865E842d2754b1fd335E55767.png",
"decimals": 18,
"logoUri": "https://safe-transaction-assets.safe.global/tokens/logos/0x56EBDaE96d179549f279ea0cFEa3b3432B8Cd2bC.png",
"trusted": false
},
{
"type": "ERC20",
"address": "0x56EBDaE96d179549f279ea0cFEa3b3432B8Cd2bC",
"address": "0x85A7a676D610A95865E842d2754b1fd335E55767",
"name": "",
"symbol": "",
"decimals": 18,
"logoUri": "https://safe-transaction-assets.safe.global/tokens/logos/0x56EBDaE96d179549f279ea0cFEa3b3432B8Cd2bC.png",
"decimals": 7,
"logoUri": "https://safe-transaction-assets.safe.global/tokens/logos/0x85A7a676D610A95865E842d2754b1fd335E55767.png",
"trusted": false
}
]
Expand Down
6 changes: 6 additions & 0 deletions components/ApiReference/examples/-v2-delegates--get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"count": 0,
"next": null,
"previous": null,
"results": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Deleted"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"address": "0x18F36D3222324DdAC1eFD0a524aabFb9D77D8041",
"tokenName": "Glarbs",
"tokenSymbol": "GLARB",
"logoUri": "https://safe-transaction-assets.safe.global/tokens/logos/0x18F36D3222324DdAC1eFD0a524aabFb9D77D8041.png",
"id": "2098",
"uri": "https://tokenofinfection.com/metadata/human/2098",
"name": null,
"description": null,
"imageUri": null,
"metadata": {}
}
]
}
Loading
Loading