-
Notifications
You must be signed in to change notification settings - Fork 237
feat: add conflux network #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kvhnuke
merged 2 commits into
enkryptcom:devop/packeupdates-0512
from
conflux-fans:inte/conflux
May 12, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,84 @@ | ||
| import { NFTCollection, NFTType, NFTItem } from '@/types/nft'; | ||
| import { NodeType } from '@/types/provider'; | ||
| import cacheFetch from '../cache-fetch'; | ||
| import { NetworkNames } from '@enkryptcom/types'; | ||
| import { | ||
| ConfluxResponse, | ||
| ConfluxNFTItem, | ||
| NFTBalanceItem, | ||
| ListResponse, | ||
| NFTItemWithDesc, | ||
| } from './types/conflux'; | ||
|
|
||
| const CONFLUX_ENDPOINT = 'https://evmapi.confluxscan.org'; | ||
| const CACHE_TTL = 60 * 1000; | ||
|
|
||
| // will fetch most 100 collections | ||
| // every collection will have most 100 items | ||
| export default async ( | ||
| network: NodeType, | ||
| address: string, | ||
| ): Promise<NFTCollection[]> => { | ||
| if (network.name !== NetworkNames.Conflux) | ||
| throw new Error('Conflux: network not supported'); | ||
| let allItems: NFTCollection[] = []; | ||
|
|
||
| let nftBalances: ConfluxResponse = await cacheFetch( | ||
| { | ||
| url: `${CONFLUX_ENDPOINT}/nft/balances?owner=${address}&skip=0&limit=100`, | ||
| }, | ||
| CACHE_TTL, | ||
| ); | ||
| if (nftBalances.status !== '1' || nftBalances.result.total === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| for (let collection of nftBalances.result | ||
| .list as unknown as NFTBalanceItem[]) { | ||
| let contract = collection.contract; | ||
|
|
||
| let items = await getCollectionItems(contract, address); | ||
| if (!items.length) { | ||
| continue; | ||
| } | ||
|
|
||
| let nftCollection: NFTCollection = { | ||
| name: collection.name, | ||
| image: collection.iconUrl || '', | ||
| description: items[0].description, | ||
| contract, | ||
| items, | ||
| }; | ||
| allItems.push(nftCollection); | ||
| } | ||
|
|
||
| return allItems; | ||
| }; | ||
|
|
||
| async function getCollectionItems( | ||
| contract: string, | ||
| address: string, | ||
| ): Promise<NFTItemWithDesc[]> { | ||
| let itemResponse: ConfluxResponse = await cacheFetch( | ||
| { | ||
| url: `${CONFLUX_ENDPOINT}/nft/tokens?contract=${contract}&owner=${address}&skip=0&limit=100&withBrief=${true}&withMetadata=${true}&suppressMetadataError=${true}`, | ||
| }, | ||
| CACHE_TTL, | ||
| ); | ||
|
|
||
| if (itemResponse.status !== '1') { | ||
| return []; | ||
| } | ||
| let items: ConfluxNFTItem[] = itemResponse.result | ||
| .list as unknown as ConfluxNFTItem[]; | ||
|
|
||
| return items.map(item => ({ | ||
| name: item.name, | ||
| id: item.tokenId, | ||
| contract: item.contract, | ||
| image: item.image, | ||
| description: item.description, | ||
| url: `https://evm.confluxscan.org/nft/${item.contract}/${item.tokenId}`, | ||
| type: item.type === 'ERC721' ? NFTType.ERC721 : NFTType.ERC1155, | ||
| })); | ||
| } | ||
This file contains hidden or 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,39 @@ | ||
| import { NFTItem } from '@/types/nft'; | ||
|
|
||
| export interface ConfluxNFTItem { | ||
| owner: string; | ||
| contract: string; | ||
| tokenId: string; | ||
| amount: string; | ||
| type: string; | ||
| name: string; | ||
| image: string; | ||
| description: string; | ||
| rawData: object; | ||
| } | ||
|
|
||
| export interface NFTBalanceItem { | ||
| owner: string; | ||
| contract: string; | ||
| balance: string; | ||
| name: string; | ||
| symbol: string; | ||
| type: string; | ||
| website: string | null; | ||
| iconUrl: string | null; | ||
| } | ||
|
|
||
| export interface ListResponse { | ||
| total: number; | ||
| list: object[]; | ||
| } | ||
|
|
||
| export interface ConfluxResponse { | ||
| status: string; | ||
| message: string; | ||
| result: ListResponse; | ||
| } | ||
|
|
||
| export interface NFTItemWithDesc extends NFTItem { | ||
| description: string; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
packages/extension/src/providers/ethereum/networks/conflux.ts
This file contains hidden or 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,29 @@ | ||
| import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network'; | ||
| import { NetworkNames } from '@enkryptcom/types'; | ||
| import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler'; | ||
| import { EtherscanActivity } from '../libs/activity-handlers'; | ||
| import icon from './icons/conflux.png'; | ||
| import assetsInfoHandler from '@/providers/ethereum/libs/assets-handlers/assetinfo-mew'; | ||
| import NFTHandler from '@/libs/nft-handlers/conflux'; | ||
|
|
||
| const confluxOptions: EvmNetworkOptions = { | ||
| name: NetworkNames.Conflux, | ||
| name_long: 'Conflux eSpace', | ||
| homePage: 'https://confluxnetwork.org/', | ||
| blockExplorerTX: 'https://evm.confluxscan.org/tx/[[txHash]]', | ||
| blockExplorerAddr: 'https://evm.confluxscan.org/address/[[address]]', | ||
| chainID: '0x406', | ||
| isTestNetwork: false, | ||
| currencyName: 'CFX', | ||
| currencyNameLong: 'CFX', | ||
| node: 'https://evm.confluxrpc.com', | ||
| icon, | ||
| NFTHandler, | ||
| coingeckoID: 'conflux', | ||
| assetsInfoHandler, | ||
| activityHandler: wrapActivityHandler(EtherscanActivity), | ||
| }; | ||
|
|
||
| const conflux = new EvmNetwork(confluxOptions); | ||
|
|
||
| export default conflux; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.