-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/safari-support
- Loading branch information
Showing
89 changed files
with
2,329 additions
and
917 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 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
83 changes: 83 additions & 0 deletions
83
packages/extension/src/libs/nft-handlers/simplehash-ordinals.ts
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,83 @@ | ||
import { NFTCollection, NFTItem, NFTType } from "@/types/nft"; | ||
import cacheFetch from "../cache-fetch"; | ||
import { NetworkNames } from "@enkryptcom/types"; | ||
import { SHOrdinalsNFTType, SHOrdinalsResponse } from "./types/simplehash"; | ||
import { BaseNetwork } from "@/types/base-network"; | ||
const SH_ENDPOINT = "https://partners.mewapi.io/nfts/"; | ||
const CACHE_TTL = 1 * 1000; | ||
export default async ( | ||
network: BaseNetwork, | ||
address: string | ||
): Promise<NFTCollection[]> => { | ||
const supportedNetworks = { | ||
[NetworkNames.Bitcoin]: "bitcoin", | ||
}; | ||
if (!Object.keys(supportedNetworks).includes(network.name)) | ||
throw new Error("Simplehash: network not supported"); | ||
let allItems: SHOrdinalsNFTType[] = []; | ||
const fetchAll = (continuation?: string): Promise<void> => { | ||
const query = continuation | ||
? continuation | ||
: `${SH_ENDPOINT}owners?chains=${ | ||
supportedNetworks[network.name as keyof typeof supportedNetworks] | ||
}&wallet_addresses=${network.displayAddress(address)}`; | ||
return cacheFetch( | ||
{ | ||
url: query, | ||
}, | ||
CACHE_TTL | ||
).then((json) => { | ||
const items: SHOrdinalsNFTType[] = (json.result as SHOrdinalsResponse) | ||
.nfts; | ||
allItems = allItems.concat(items); | ||
if (json.result.next) return fetchAll(json.result.next); | ||
}); | ||
}; | ||
await fetchAll(); | ||
if (!allItems || !allItems.length) return []; | ||
const collections: Record<string, NFTCollection> = {}; | ||
allItems.forEach((item) => { | ||
const collectionName = | ||
item.extra_metadata.ordinal_details.protocol_name === "brc-20" | ||
? "BRC20" | ||
: item.collection.name | ||
? item.collection.name | ||
: "Unknown"; | ||
const contractAddress = | ||
item.collection.collection_id || item.contract_address; | ||
if (!item.image_url && !item.previews.image_medium_url) return; | ||
if (!collectionName) return; | ||
if (collections[contractAddress]) { | ||
const tItem: NFTItem = { | ||
contract: contractAddress, | ||
id: item.extra_metadata.ordinal_details.location, | ||
image: item.previews.image_medium_url, | ||
name: item.contract.name, | ||
url: `https://ordinals.com/inscription/${item.contract_address}`, | ||
type: NFTType.Ordinals, | ||
}; | ||
collections[contractAddress].items.push(tItem); | ||
} else { | ||
const ret: NFTCollection = { | ||
name: collectionName, | ||
description: item.collection.description, | ||
image: | ||
item.collection.image_url || | ||
require("@action/assets/common/not-found.jpg"), | ||
contract: contractAddress, | ||
items: [ | ||
{ | ||
contract: contractAddress, | ||
id: item.extra_metadata.ordinal_details.location, | ||
image: item.image_url || item.previews.image_medium_url, | ||
name: item.contract.name, | ||
url: `https://ordinals.com/inscription/${item.contract_address}`, | ||
type: NFTType.Ordinals, | ||
}, | ||
], | ||
}; | ||
collections[contractAddress] = ret; | ||
} | ||
}); | ||
return Object.values(collections); | ||
}; |
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 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
Oops, something went wrong.
3c3310e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/3df95dd2c5128ba3623b88232387aaada4c5275359a4ae9e3bcc73c8aaf96bb5
firefox:
https://www.virustotal.com/gui/file/8ad0efec623282dc81a03c09bb383ed3d9fc8fcd327877dfb828c7a8bc3cd846