Skip to content

Commit

Permalink
feat: migrate nft api
Browse files Browse the repository at this point in the history
  • Loading branch information
qwang1113 committed Oct 26, 2023
1 parent f68c0b8 commit 95dde52
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 2,159 deletions.
13 changes: 0 additions & 13 deletions packages/engine/src/managers/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import { IDecodedTxActionType, IDecodedTxDirection } from '../vaults/types';

import { isAllNetworks } from './network';

export function getNFTListKey(accountId: string, networkId: string) {
return `${accountId.toLowerCase()}-${networkId}`.toLowerCase();
}

export const isCollectibleSupportedChainId = (networkId?: string) => {
if (!networkId) return false;
if (isAllNetworks(networkId)) return true;
Expand Down Expand Up @@ -413,12 +409,3 @@ export type BRC20TextProps = {
lim?: string; // deploy
max?: string; // deploy
};

export function parseTextProps(content: string) {
try {
const json = JSON.parse(content) as BRC20TextProps;
return json;
} catch (error) {
console.log('parse InscriptionText error = ', error);
}
}
92 changes: 2 additions & 90 deletions packages/kit-bg/src/services/ServiceNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import simpleDb from '@onekeyhq/engine/src/dbs/simple/simpleDb';
import { getFiatEndpoint } from '@onekeyhq/engine/src/endpoint';
import { OneKeyInternalError } from '@onekeyhq/engine/src/errors';
import * as nft from '@onekeyhq/engine/src/managers/nft';
import { NFTDataType, getNFTListKey } from '@onekeyhq/engine/src/managers/nft';
import type { Account } from '@onekeyhq/engine/src/types/account';
import { NFTDataType } from '@onekeyhq/engine/src/managers/nft';
import type {
Collection,
CollectionAttribute,
Expand All @@ -14,16 +13,12 @@ import type {
NFTAssetMeta,
NFTBTCAssetModel,
NFTListItems,
NFTMarketCapCollection,
NFTMarketRanking,
NFTPNL,
NFTServiceResp,
NFTTransaction,
} from '@onekeyhq/engine/src/types/nft';
import {
setNFTPriceType,
setNFTSymbolPrice,
} from '@onekeyhq/kit/src/store/reducers/nft';
import { setNFTPriceType } from '@onekeyhq/kit/src/store/reducers/nft';
import { EOverviewScanTaskType } from '@onekeyhq/kit/src/views/Overview/types';
import {
backgroundClass,
Expand Down Expand Up @@ -210,29 +205,6 @@ class ServiceNFT extends ServiceBase {
}

@backgroundMethod()
async getMarketCapCollection({
chain,
limit,
}: {
chain?: string;
limit?: number;
}) {
let url = `${this.baseUrl}/market/marketCap?chain=${
chain ?? OnekeyNetwork.eth
}`;
if (limit) {
url += `&limit=${limit}`;
}
const { data, success } = await this.client
.get<NFTServiceResp<NFTMarketCapCollection[]>>(url)
.then((resp) => resp.data)
.catch(() => ({ success: false, data: [] as NFTMarketCapCollection[] }));
if (!success) {
return [];
}
return data;
}

@backgroundMethod()
async getMarketRanking({ chain, time }: { chain?: string; time?: string }) {
const url = `${this.baseUrl}/market/ranking?chain=${
Expand All @@ -248,34 +220,6 @@ class ServiceNFT extends ServiceBase {
return data;
}

@backgroundMethod()
async getMarketCollection() {
const url = `${this.baseUrl}/market/collection`;
const { data, success } = await this.client
.get<NFTServiceResp<Collection[]>>(url)
.then((resp) => resp.data)
.catch(() => ({ success: false, data: [] as Collection[] }));
if (!success) {
return [];
}
return data;
}

@backgroundMethod()
async getLiveMinting({ chain, limit }: { chain?: string; limit?: number }) {
const url = `${this.baseUrl}/market/liveMint?chain=${
chain ?? OnekeyNetwork.eth
}&limit=${limit ?? 5}`;
const { data, success } = await this.client
.get<NFTServiceResp<NFTAsset[]>>(url)
.then((resp) => resp.data)
.catch(() => ({ success: false, data: [] as NFTAsset[] }));
if (!success) {
return [];
}
return data;
}

@backgroundMethod()
async batchAsset(params: {
ignoreError?: boolean;
Expand Down Expand Up @@ -326,23 +270,6 @@ class ServiceNFT extends ServiceBase {
return data;
}

@backgroundMethod()
async batchLocalCollection({
networkId,
account,
}: {
networkId: string;
account: Account;
}): Promise<NFTAssetMeta | undefined> {
const key = getNFTListKey(account.address, networkId);
const items = await simpleDb.nft.getNFTs(key);
if (items) {
const { engine } = this.backgroundApi;
const vault = await engine.getVault({ networkId, accountId: account.id });
return vault.getUserNFTAssets({ serviceData: items });
}
}

@backgroundMethod()
async fetchNFT({
accountId,
Expand Down Expand Up @@ -388,21 +315,6 @@ class ServiceNFT extends ServiceBase {
return nft.getAllAssetsFromLocal(params);
}

@backgroundMethod()
async fetchSymbolPrice(networkId: string) {
const price = await nft.getNFTSymbolPrice(networkId);
if (price) {
const { dispatch } = this.backgroundApi;
dispatch(
setNFTSymbolPrice({
networkId,
price,
}),
);
return price;
}
}

@backgroundMethod()
updatePriceType(priceType: 'floorPrice' | 'lastSalePrice') {
const { dispatch } = this.backgroundApi;
Expand Down
44 changes: 0 additions & 44 deletions packages/kit/src/routes/Root/Main/Tab/routes/AppRootTabNFT.ts

This file was deleted.

23 changes: 1 addition & 22 deletions packages/kit/src/store/reducers/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ type NFTPrice = 'floorPrice' | 'lastSalePrice';

type InitialState = {
nftPrice: Record<string, Record<string, Record<NFTPrice, number>>>;
nftSymbolPrice: Record<string, number>;
disPlayPriceType: NFTPrice;
};

const initialState: InitialState = {
nftPrice: {},
nftSymbolPrice: {},
disPlayPriceType: 'lastSalePrice',
};

Expand All @@ -22,11 +20,6 @@ type NFTPricePayloadAction = {
price: Record<NFTPrice, number>;
};

type NFTSymbolPricePayloadAction = {
networkId?: string | null;
price: number;
};

export const networkSlice = createSlice({
name: 'nft',
initialState,
Expand All @@ -49,23 +42,9 @@ export const networkSlice = createSlice({
state.disPlayPriceType = action.payload;
}
},
setNFTSymbolPrice(
state,
action: PayloadAction<NFTSymbolPricePayloadAction>,
) {
const { networkId, price } = action.payload;
if (!networkId) {
return;
}
const oldPrice = state.nftSymbolPrice[networkId] ?? {};
if (oldPrice !== price) {
state.nftSymbolPrice[networkId] = price;
}
},
},
});

export const { setNFTPrice, setNFTPriceType, setNFTSymbolPrice } =
networkSlice.actions;
export const { setNFTPrice, setNFTPriceType } = networkSlice.actions;

export default networkSlice.reducer;
71 changes: 0 additions & 71 deletions packages/kit/src/views/NFTMarket/DateSelector/index.tsx

This file was deleted.

65 changes: 0 additions & 65 deletions packages/kit/src/views/NFTMarket/Home/Banner/index.tsx

This file was deleted.

Loading

0 comments on commit 95dde52

Please sign in to comment.