From ccfb3bd3b2d1e90f969140156d53f8f684c32495 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Thu, 19 Mar 2020 11:05:06 -0300 Subject: [PATCH] fix: collectibles not displayed while disconnected Instead of picking the network Id from the web3 provider, we rely on the network name specified in the env variable. fixes issue #669 --- src/logic/collectibles/sources/OpenSea.js | 15 +++++++-------- .../store/actions/fetchCollectibles.js | 7 +++---- .../components/Balances/Collectibles/types.js | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/logic/collectibles/sources/OpenSea.js b/src/logic/collectibles/sources/OpenSea.js index 204fdbee..8d83614a 100644 --- a/src/logic/collectibles/sources/OpenSea.js +++ b/src/logic/collectibles/sources/OpenSea.js @@ -1,6 +1,7 @@ // @flow import { RateLimit } from 'async-sema' +import { ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3' import type { CollectibleMetadataSource, CollectiblesInfo, @@ -15,11 +16,9 @@ import { OPENSEA_API_KEY } from '~/utils/constants' class OpenSea implements CollectibleMetadataSource { _rateLimit = async () => {} - _endpointsUrls: { [key: number]: string } = { - // $FlowFixMe - 1: 'https://api.opensea.io/api/v1', - // $FlowFixMe - 4: 'https://rinkeby-api.opensea.io/api/v1', + _endpointsUrls: { [key: string]: string } = { + [ETHEREUM_NETWORK.MAINNET]: 'https://api.opensea.io/api/v1', + [ETHEREUM_NETWORK.RINKEBY]: 'https://rinkeby-api.opensea.io/api/v1', } _fetch = async (url: string) => { @@ -91,12 +90,12 @@ class OpenSea implements CollectibleMetadataSource { * Fetches from OpenSea the list of collectibles, grouped by category, * for the provided Safe Address in the specified Network * @param {string} safeAddress - * @param {number} networkId + * @param {string} network * @returns {Promise<{ nftAssets: Map, nftTokens: Array }>} */ - async fetchAllUserCollectiblesByCategoryAsync(safeAddress: string, networkId: number) { + async fetchAllUserCollectiblesByCategoryAsync(safeAddress: string, network: string) { // eslint-disable-next-line no-underscore-dangle - const metadataSourceUrl = this._endpointsUrls[networkId] + const metadataSourceUrl = this._endpointsUrls[network] const url = `${metadataSourceUrl}/assets/?owner=${safeAddress}` // eslint-disable-next-line no-underscore-dangle const assetsResponse = await this._fetch(url) diff --git a/src/logic/collectibles/store/actions/fetchCollectibles.js b/src/logic/collectibles/store/actions/fetchCollectibles.js index eb68bcde..0ed61a56 100644 --- a/src/logic/collectibles/store/actions/fetchCollectibles.js +++ b/src/logic/collectibles/store/actions/fetchCollectibles.js @@ -1,16 +1,15 @@ // @flow import type { Dispatch } from 'redux' +import { getNetwork } from '~/config' import { getConfiguredSource } from '~/logic/collectibles/sources' import { addNftAssets, addNftTokens } from '~/logic/collectibles/store/actions/addCollectibles' -import { PROVIDER_REDUCER_ID } from '~/logic/wallets/store/reducer/provider' import { safeParamAddressFromStateSelector } from '~/routes/safe/store/selectors' import type { GlobalState } from '~/store' const fetchCollectibles = () => async (dispatch: Dispatch, getState) => { - const state = getState() - const { network } = state[PROVIDER_REDUCER_ID] - const safeAddress = safeParamAddressFromStateSelector(state) + const network = getNetwork() + const safeAddress = safeParamAddressFromStateSelector(getState()) || '' const source = getConfiguredSource() const collectibles = await source.fetchAllUserCollectiblesByCategoryAsync(safeAddress, network) diff --git a/src/routes/safe/components/Balances/Collectibles/types.js b/src/routes/safe/components/Balances/Collectibles/types.js index 91122d28..7795addb 100644 --- a/src/routes/safe/components/Balances/Collectibles/types.js +++ b/src/routes/safe/components/Balances/Collectibles/types.js @@ -205,5 +205,5 @@ export type CollectiblesInfo = { export interface CollectibleMetadataSource { constructor(options: { rps: number }): void; - fetchAllUserCollectiblesByCategoryAsync(safeAddress: string, networkId: number): Promise; + fetchAllUserCollectiblesByCategoryAsync(safeAddress: string, network: string): Promise; }