Skip to content

Commit

Permalink
export tranfrom functions and monkey-patch api bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Akbarov committed Jul 26, 2022
1 parent 5453dd1 commit 7ca0fb3
Show file tree
Hide file tree
Showing 9 changed files with 1,134 additions and 1,193 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ yarn-error.log
node_modules/
.DS_Store
.husky
notes.md
yalc.lock
.yalc
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zoralabs/nft-hooks",
"version": "1.1.7",
"version": "1.1.8",
"description": "Generic react hooks for fetching zora auctions, nfts, and data on arbitary 721s. Powers nft-components.",
"repository": "https://github.com/ourzora/nft-hooks",
"homepage": "https://github.com/ourzora/nft-hooks#README",
Expand Down Expand Up @@ -68,7 +68,7 @@
"@ethersproject/address": "^5.6.0",
"@ethersproject/bytes": "^5.6.1",
"@types/deepmerge": "^2.2.0",
"@zoralabs/zdk": "2.1.1",
"@zoralabs/zdk": "2.1.3",
"big.js": "^6.1.0",
"cross-fetch": "^3.1.4",
"dataloader": "^2.0.0",
Expand All @@ -82,4 +82,4 @@
"singleQuote": true,
"printWidth": 90
}
}
}
95 changes: 68 additions & 27 deletions src/backends/zdk/ZDKDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { MEDIA_SOURCES, NFTIdentifier } from '../../types';
import { NotFoundError } from '../../fetcher/ErrorUtils';
import { resolveSortKey } from './utils/resolveSortKey';
import { dateToISO } from './utils/dateToISO';
import { processEvents } from './transformUtils/processEvents';
import { processMarkets } from './transformUtils/processMarkets';
import { transformEvents } from './transformUtils/transformEvents';
import { transformMarkets } from './transformUtils/transformMarkets';
import { getChainFromNetwork } from './utils/getChainFromNetwork';
import DataLoader from 'dataloader';

Expand All @@ -34,7 +34,9 @@ export {
NFTQuery,
} from '../../types/NFTQuery';

export function transformNFTZDK(tokenResponse: SharedTokenResponse, object?: NFTObject) {
export { transformNFTZDK, transformEvents, transformMarkets };

function transformNFTZDK(tokenResponse: SharedTokenResponse, object?: NFTObject) {
if (!object) {
object = { rawData: {} };
}
Expand Down Expand Up @@ -68,13 +70,13 @@ export function transformNFTZDK(tokenResponse: SharedTokenResponse, object?: NFT

// Response of token query
if (tokenResponse.__typename === 'TokenWithFullMarketHistory') {
object.markets = processMarkets(tokenResponse.markets);
object.events = processEvents(tokenResponse.events);
object.markets = transformMarkets(tokenResponse.markets);
object.events = transformEvents(tokenResponse.events);
}

// Response of tokens (plural) query
if (tokenResponse.__typename === 'TokenWithMarketsSummary') {
object.markets = processMarkets(tokenResponse.marketsSummary);
object.markets = transformMarkets(tokenResponse.marketsSummary);
}

object.metadata = {
Expand All @@ -90,30 +92,69 @@ export function transformNFTZDK(tokenResponse: SharedTokenResponse, object?: NFT
raw: token.metadata,
};

let thumbnail = undefined;

if (
token.image?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.image.mediaEncoding.thumbnail
) {
thumbnail = {
uri: token.image.mediaEncoding.thumbnail,
};
}

if (
token.content?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.content.mediaEncoding.thumbnail
) {
thumbnail = {
uri: token.content.mediaEncoding.thumbnail,
};
}

let large = undefined;
if (
token.image?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.image.mediaEncoding.large
) {
large = {
uri: token.image.mediaEncoding.large,
};
}
if (
token.content?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.content.mediaEncoding.large
) {
large = {
uri: token.content.mediaEncoding.large,
};
}

let poster = undefined;
if (
token.image?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.image.mediaEncoding.poster
) {
poster = {
uri: token.image.mediaEncoding.poster,
};
}

if (
token.content?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.content.mediaEncoding.poster
) {
poster = {
uri: token.content.mediaEncoding.poster,
};
}

object.media = {
source: MEDIA_SOURCES.ZORA,
mimeType: token.image?.mimeType || undefined,
thumbnail:
token.image?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.image.mediaEncoding.thumbnail
? {
uri: token.image.mediaEncoding.thumbnail,
}
: undefined,
large:
token.image?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.image.mediaEncoding.large
? {
uri: token.image.mediaEncoding.large,
}
: undefined,
poster:
token.image?.mediaEncoding?.__typename === 'ImageEncodingTypes' &&
token.image.mediaEncoding.poster
? {
uri: token.image.mediaEncoding.poster,
}
: undefined,
thumbnail,
large,
poster,
image: token.image?.url
? {
mime: token.image.mimeType || undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
} from '../../../types';
import { ZERO_ADDRESS } from '../../../constants/addresses';
import { dateToISO } from '../utils/dateToISO';
import { processMarketEvent } from './processMarketEvent';
import { transformMarketEvent } from './transformMarketEvent';

export function processEvents(events: EventInfoFragment[]): NormalizedEvent[] {
export function transformEvents(events: EventInfoFragment[]): NormalizedEvent[] {
const eventsList: NormalizedEvent[] = [];

events.forEach((tokenEvent) => {
Expand Down Expand Up @@ -72,7 +72,7 @@ export function processEvents(events: EventInfoFragment[]): NormalizedEvent[] {
tokenEvent.eventType === EventType.V1MarketEvent &&
tokenEvent.properties.__typename === 'V1MarketEvent'
) {
const e = processMarketEvent(tokenEvent);
const e = transformMarketEvent(tokenEvent);

if (e) {
eventsList.push(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../../../types';
import { dateToISO } from '../utils/dateToISO';

export function processMarketEvent(e: EventInfoFragment): NormalizedEvent | undefined {
export function transformMarketEvent(e: EventInfoFragment): NormalizedEvent | undefined {
if (
!(
e.eventType === EventType.V1MarketEvent &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
MarketResponseFragmentItem,
} from '../utils/getStandardMarketData';

export function processMarkets(markets: MarketResponseFragmentItem[]) {
export function transformMarkets(markets: MarketResponseFragmentItem[]) {
const getReserveAuctionStatus = (status: V2AuctionStatus) => {
if (status === V2AuctionStatus.Active) {
return MARKET_INFO_STATUSES.ACTIVE;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import merge from 'deepmerge';
import useSWR, { SWRConfiguration } from 'swr';
import { NFTStrategy } from '../strategies/NFTStrategy';
import { NFTObject } from '../types/NFTInterface';
import { log } from '../utils/logger';

export type useNFTType = {
currencyLoaded: boolean;
Expand All @@ -13,7 +14,6 @@ export type useNFTType = {
data?: NFTObject;
};


/**
* Fetches on-chain NFT data and pricing for the given nft contract address and id
*
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true
},
"include": ["src", "graph-schemas"]
"include": ["src", "graph-schemas" ]
}
Loading

0 comments on commit 7ca0fb3

Please sign in to comment.