Remove OpenSea

This commit is contained in:
katspaugh 2021-06-08 11:23:24 +02:00
parent 29ebf6667e
commit fc7eed659f
6 changed files with 1 additions and 1271 deletions

View File

@ -172,7 +172,6 @@
"@sentry/tracing": "^6.3.5",
"@truffle/contract": "^4.3.18",
"@unstoppabledomains/resolution": "^1.17.0",
"async-sema": "^3.1.0",
"axios": "0.21.1",
"bignumber.js": "9.0.1",
"bnc-onboard": "~1.25.0",

View File

@ -1,11 +0,0 @@
import OpenSea from 'src/logic/collectibles/sources/OpenSea'
import mockedOpenSea from './mocked_opensea.json'
class MockedOpenSea extends OpenSea {
_fetch: any = async () => {
await this._rateLimit()
return { json: () => mockedOpenSea }
}
}
export default MockedOpenSea

View File

@ -1,97 +0,0 @@
import { RateLimit } from 'async-sema'
import { getNetworkId } from 'src/config'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d'
import { Collectibles, NFTAssets, NFTTokens, OpenSeaAssets } from 'src/logic/collectibles/sources/collectibles.d'
import NFTIcon from 'src/routes/safe/components/Balances/assets/nft_icon.png'
import { OPENSEA_API_KEY } from 'src/utils/constants'
class OpenSea {
_rateLimit = async (): Promise<void> => {}
_endpointsUrls = {
[ETHEREUM_NETWORK.MAINNET]: 'https://api.opensea.io/api/v1',
[ETHEREUM_NETWORK.RINKEBY]: 'https://rinkeby-api.opensea.io/api/v1',
}
_fetch = async (url: string): Promise<Response> => {
// eslint-disable-next-line no-underscore-dangle
return fetch(url, {
headers: { 'X-API-KEY': OPENSEA_API_KEY || '' },
})
}
/**
* OpenSea class constructor
* @param {object} options
* @param {number} options.rps - requests per second
*/
constructor(options: { rps: number }) {
// eslint-disable-next-line no-underscore-dangle
this._rateLimit = RateLimit(options.rps, { timeUnit: 60 * 1000, uniformDistribution: true })
}
static extractAssets(assets: OpenSeaAssets): NFTAssets {
const extractNFTAsset = (asset) => ({
address: asset.asset_contract.address,
assetContract: asset.asset_contract,
collection: asset.collection,
description: asset.asset_contract.name,
image: asset.asset_contract.image_url || NFTIcon,
name: asset.collection.name,
numberOfTokens: 1,
slug: asset.collection.slug,
symbol: asset.asset_contract.symbol,
})
return assets.reduce((acc, asset) => {
const address = asset.asset_contract.address
if (acc[address] === undefined) {
acc[address] = extractNFTAsset(asset)
} else {
// By default, extractNFTAsset sets `numberOfTokens` to 1,
// counting the asset recently processed.
// If it happens to already exist the asset in the map,
// then we just increment the `numberOfTokens` value by 1.
acc[address].numberOfTokens = acc[address].numberOfTokens + 1
}
return acc
}, {})
}
static extractTokens(assets: OpenSeaAssets): NFTTokens {
return assets.map((asset) => ({
assetAddress: asset.asset_contract.address,
color: asset.background_color,
description: asset.description,
image: asset.image_thumbnail_url || NFTIcon,
name: asset.name || `${asset.asset_contract.name} - #${asset.token_id}`,
tokenId: asset.token_id,
}))
}
static extractCollectiblesInfo(assetResponseJson: { assets: OpenSeaAssets }): Collectibles {
return {
nftAssets: OpenSea.extractAssets(assetResponseJson.assets),
nftTokens: OpenSea.extractTokens(assetResponseJson.assets),
}
}
/**
* Fetches from OpenSea the list of collectibles, grouped by category,
* for the provided Safe Address in the specified Network
* @param {string} safeAddress
* @returns {Promise<Collectibles>}
*/
async fetchCollectibles(safeAddress: string): Promise<Collectibles> {
const metadataSourceUrl = this._endpointsUrls[getNetworkId()]
const url = `${metadataSourceUrl}/assets/?owner=${safeAddress}`
const assetsResponse = await this._fetch(url)
const assetsResponseJson = await assetsResponse.json()
return OpenSea.extractCollectiblesInfo(assetsResponseJson)
}
}
export default OpenSea

View File

@ -1,15 +1,10 @@
import MockedOpenSea from 'src/logic/collectibles/sources/MockedOpenSea'
import OpenSea from 'src/logic/collectibles/sources/OpenSea'
import Gnosis from 'src/logic/collectibles/sources/Gnosis'
import { COLLECTIBLES_SOURCE } from 'src/utils/constants'
const SOURCES = {
opensea: new OpenSea({ rps: 4 }),
gnosis: new Gnosis(),
mockedopensea: new MockedOpenSea({ rps: 4 }),
}
type Sources = typeof SOURCES
export const getConfiguredSource = (): Sources['opensea'] | Sources['mockedopensea'] | Sources['gnosis'] =>
SOURCES[COLLECTIBLES_SOURCE.toLowerCase()]
export const getConfiguredSource = (): Sources['gnosis'] => SOURCES[COLLECTIBLES_SOURCE.toLowerCase()]

File diff suppressed because it is too large Load Diff

View File

@ -4816,11 +4816,6 @@ async-mutex@^0.2.6:
dependencies:
tslib "^2.0.0"
async-sema@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/async-sema/-/async-sema-3.1.0.tgz#3a813beb261e4cc58b19213916a48e931e21d21e"
integrity sha512-+JpRq3r0zjpRLDruS6q/nC4V5tzsaiu07521677Mdi5i+AkaU/aNJH38rYHJVQ4zvz+SSkjgc8FUI7qIZrR+3g==
async@0.9.x:
version "0.9.2"
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"