This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LIVE-1911][LIVE-1912] Feature - Add collection name resolver to eth …
…familly (#1863) * Change nfts resolvers from Bridge type * Update eth nft resolvers & add collection resolver * Add loadCollectionMetadata to nft context * Change eth NFT prepareTransaction to use collection call instead of nft metadata call
- Loading branch information
1 parent
73686de
commit f13dd89
Showing
10 changed files
with
320 additions
and
100 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
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 was deleted.
Oops, something went wrong.
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,79 @@ | ||
import { | ||
CurrencyBridge, | ||
NFTCollectionMetadataResponse, | ||
NFTMetadataResponse, | ||
} from "../../types"; | ||
import { getCryptoCurrencyById } from "../../currencies"; | ||
import { metadataCallBatcher } from "../../nft"; | ||
|
||
const SUPPORTED_CHAIN_IDS = new Set([ | ||
1, // Ethereum | ||
137, // Polygon | ||
]); | ||
|
||
type NftResolvers = NonNullable<CurrencyBridge["nftResolvers"]>; | ||
|
||
export const nftMetadata: NftResolvers["nftMetadata"] = async ({ | ||
contract, | ||
tokenId, | ||
currencyId, | ||
metadata, | ||
}): Promise<NFTMetadataResponse> => { | ||
// This is for test/mock purposes | ||
if (typeof metadata !== "undefined") { | ||
return { | ||
status: 200, | ||
result: { | ||
contract, | ||
tokenId, | ||
...metadata, | ||
}, | ||
}; | ||
} | ||
|
||
const currency = getCryptoCurrencyById(currencyId); | ||
const chainId = currency?.ethereumLikeInfo?.chainId; | ||
|
||
if (!chainId || !SUPPORTED_CHAIN_IDS.has(chainId)) { | ||
throw new Error("Ethereum Bridge NFT Resolver: Unsupported chainId"); | ||
} | ||
|
||
const response = (await metadataCallBatcher(currency).loadNft({ | ||
contract, | ||
tokenId, | ||
})) as NFTMetadataResponse; | ||
|
||
return response; | ||
}; | ||
|
||
export const collectionMetadata: NftResolvers["collectionMetadata"] = async ({ | ||
contract, | ||
currencyId, | ||
metadata, | ||
}): Promise<NFTCollectionMetadataResponse> => { | ||
// This is for test/mock purposes | ||
if (typeof metadata !== "undefined") { | ||
return { | ||
status: 200, | ||
result: { | ||
contract, | ||
...metadata, | ||
}, | ||
}; | ||
} | ||
|
||
const currency = getCryptoCurrencyById(currencyId); | ||
const chainId = currency?.ethereumLikeInfo?.chainId; | ||
|
||
if (!chainId || !SUPPORTED_CHAIN_IDS.has(chainId)) { | ||
throw new Error("Ethereum Bridge NFT Resolver: Unsupported chainId"); | ||
} | ||
|
||
const response = (await metadataCallBatcher(currency).loadCollection({ | ||
contract, | ||
})) as NFTCollectionMetadataResponse; | ||
|
||
return response; | ||
}; | ||
|
||
export default { nftMetadata, collectionMetadata }; |
Oops, something went wrong.