-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add svg route * route fix * cleanup * chainrouter * yarn cleanup --------- Co-authored-by: Trajan0x <[email protected]>
- Loading branch information
Showing
5 changed files
with
105 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import express from 'express' | ||
import { BRIDGABLE_TOKENS, Token } from '@synapsecns/synapse-constants' | ||
import fetch from 'cross-fetch' | ||
|
||
const router: express.Router = express.Router() | ||
|
||
router.get('/:chainId/:address.svg', async (req, res) => { | ||
const chainId = parseInt(req.params.chainId, 10) | ||
const address = req.params.address.toLowerCase() | ||
|
||
// Find the token with matching address on the specified chain | ||
const token = Object.values(BRIDGABLE_TOKENS[chainId] || []).find( | ||
(t): t is Token => | ||
typeof t === 'object' && | ||
t !== null && | ||
'addresses' in t && | ||
Object.entries(t.addresses).some(([chain, addr]) => { | ||
const matches = | ||
parseInt(chain, 10) === chainId && addr.toLowerCase() === address | ||
return matches | ||
}) | ||
) | ||
|
||
if (!token || !token.icon) { | ||
console.log('Token not found or no icon:', { token }) | ||
res.status(404).json({ error: 'Token icon not found' }) | ||
return | ||
} | ||
|
||
try { | ||
// Fetch the image from the URL | ||
const response = await fetch(token.icon) | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch image: ${response.statusText}`) | ||
} | ||
|
||
const buffer = await response.arrayBuffer() | ||
|
||
// Set cache headers (cache for 1 week) | ||
res.set({ | ||
'Cache-Control': 'public, max-age=604800', | ||
'Content-Type': response.headers.get('content-type') || 'image/svg+xml', | ||
}) | ||
|
||
res.send(Buffer.from(buffer)) | ||
} catch (error) { | ||
console.error('Error fetching token icon:', error) | ||
res.status(500).json({ error: 'Failed to fetch token icon' }) | ||
} | ||
return | ||
}) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import express from 'express' | ||
import { CHAINS, Chain } from '@synapsecns/synapse-constants' | ||
import fetch from 'cross-fetch' | ||
|
||
const router: express.Router = express.Router() | ||
|
||
router.get('/:chainId.svg', async (req, res) => { | ||
const chainId = parseInt(req.params.chainId, 10) | ||
|
||
// Find the chain with matching ID | ||
const chain = Object.values(CHAINS).find( | ||
(c): c is Chain => | ||
typeof c === 'object' && c !== null && 'id' in c && c.id === chainId | ||
) | ||
|
||
if (!chain || !chain.chainImg) { | ||
res.status(404).json({ error: 'Chain icon not found' }) | ||
return | ||
} | ||
|
||
try { | ||
// Fetch the image from the URL | ||
const response = await fetch(chain.chainImg) | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch image: ${response.statusText}`) | ||
} | ||
|
||
const buffer = await response.arrayBuffer() | ||
|
||
// Set cache headers (cache for 1 week) | ||
res.set({ | ||
'Cache-Control': 'public, max-age=604800', | ||
'Content-Type': response.headers.get('content-type') || 'image/svg+xml', | ||
}) | ||
|
||
res.send(Buffer.from(buffer)) | ||
} catch (error) { | ||
console.error('Error fetching chain icon:', error) | ||
res.status(500).json({ error: 'Failed to fetch chain icon' }) | ||
} | ||
return | ||
}) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18757,12 +18757,7 @@ fd-slicer@~1.1.0: | |
dependencies: | ||
pend "~1.2.0" | ||
|
||
fdir@^6.2.0: | ||
version "6.4.2" | ||
resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.2.tgz#ddaa7ce1831b161bc3657bb99cb36e1622702689" | ||
integrity sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ== | ||
|
||
fdir@^6.4.2: | ||
fdir@^6.2.0, fdir@^6.4.2: | ||
version "6.4.2" | ||
resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.2.tgz#ddaa7ce1831b161bc3657bb99cb36e1622702689" | ||
integrity sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ== | ||
|
@@ -37610,12 +37605,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.0.0-1.tgz#8c3029b3ee2028306d5bcf396980623115ff8d18" | ||
integrity sha512-W7h5dEhywMKenDJh2iX/LABkbFnBxasD27oyXWDS/feDsxiw0dD5ncXdYXgkvAsXIY2MpW/ZKkr9IU30DBdMNQ== | ||
|
||
yaml@^2.3.1, yaml@^2.3.4: | ||
version "2.6.0" | ||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.6.0.tgz#14059ad9d0b1680d0f04d3a60fe00f3a857303c3" | ||
integrity sha512-a6ae//JvKDEra2kdi1qzCyrJW/WZCgFi8ydDV+eXExl95t+5R+ijnqHJbz9tmMh8FUjx3iv2fCQ4dclAQlO2UQ== | ||
|
||
yaml@^2.6.0: | ||
yaml@^2.3.1, yaml@^2.3.4, yaml@^2.6.0: | ||
version "2.6.0" | ||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.6.0.tgz#14059ad9d0b1680d0f04d3a60fe00f3a857303c3" | ||
integrity sha512-a6ae//JvKDEra2kdi1qzCyrJW/WZCgFi8ydDV+eXExl95t+5R+ijnqHJbz9tmMh8FUjx3iv2fCQ4dclAQlO2UQ== | ||
|