Skip to content
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

Removed legacy NFT collection methods #609

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import type {
BlockchainResponse,
Contact,
NFTData,
NFTModel,
NFTModel_depreciated,
NFTModelV2,
WalletResponse,
} from '../../shared/types/network-types';
Expand Down Expand Up @@ -2497,20 +2497,16 @@ export class WalletController extends BaseController {
);
};

enableNFTStorageLocal = async (token: NFTModel) => {
enableNFTStorageLocal = async (token: NFTModelV2) => {
const script = await getScripts('collection', 'enableNFTStorage');
if (token['contractName']) {
token.contract_name = token['contractName'];
token.path.storage_path = token['path']['storage'];
token.path.public_path = token['path']['public'];
}

return await userWalletService.sendTransaction(
script
.replaceAll('<NFT>', token.contract_name)
.replaceAll('<NFT>', token.contractName)
.replaceAll('<NFTAddress>', token.address)
.replaceAll('<CollectionStoragePath>', token.path.storage_path)
.replaceAll('<CollectionPublicType>', token.path.public_type)
.replaceAll('<CollectionPublicPath>', token.path.public_path),
.replaceAll('<CollectionStoragePath>', token.path.storage)
.replaceAll('<CollectionPublicType>', token.path.public)
.replaceAll('<CollectionPublicPath>', token.path.public),
[]
);
};
Expand Down
96 changes: 18 additions & 78 deletions src/background/service/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
type SignInResponse,
type UserInfoResponse,
type TokenModel,
type NFTModel,
type NFTModel_depreciated,
type StorageInfo,
type NewsItem,
type NewsConditionType,
Expand All @@ -48,6 +48,7 @@ import {
type BlockchainResponse,
type AccountInfo,
type Contact,
type NFTModelV2,
} from '../../shared/types/network-types';

import {
Expand Down Expand Up @@ -801,7 +802,7 @@ class OpenApiService {
return data;
};

getNFTList = async (network: string) => {
getNFTList = async (network: string): Promise<NFTModelV2[]> => {
const childType = await userWalletService.getActiveWallet();
let chainType = 'flow';
if (childType === 'evm') {
Expand All @@ -813,7 +814,7 @@ class OpenApiService {
return nftList;
}
const config = this.store.config.get_nft_list;
const { tokens } = await this.sendRequest(
const { tokens }: { tokens: NFTModelV2[] } = await this.sendRequest(
config.method,
config.path,
{
Expand Down Expand Up @@ -1163,18 +1164,12 @@ class OpenApiService {
return filterNetwork ? list.filter((item) => item.address) : list;
};

getAllNft = async (filterNetwork = true): Promise<NFTModel[]> => {
getAllNft = async (filterNetwork = true): Promise<NFTModelV2[]> => {
const list = await remoteFetch.nftCollection();
// const network = await userWalletService.getNetwork();
return list;
};

getAllNftV2 = async (filterNetwork = true): Promise<NFTModel[]> => {
const list = await remoteFetch.nftv2Collection();
// const network = await userWalletService.getNetwork();
return list;
};

isWalletTokenStorageEnabled = async (tokenSymbol: string) => {
// FIX ME: Get defaultTokenList from firebase remote config
const address = await userWalletService.getCurrentAddress();
Expand Down Expand Up @@ -1465,28 +1460,29 @@ class OpenApiService {
return await googleSafeHostService.getBlockList(hosts, forceCheck);
};

getEnabledNFTList = async () => {
getEnabledNFTList = async (): Promise<{ address: string; contractName: string }[]> => {
const address = await userWalletService.getCurrentAddress();

const promiseResult = await this.checkNFTListEnabledNew(address);

const promiseResult = await this.checkNFTListEnabled(address);
// const network = await userWalletService.getNetwork();
// const notEmptyTokenList = tokenList.filter(value => value.address[network] !== null && value.address[network] !== '' )
// const data = values.map((value, index) => ({isEnabled: value, token: tokenList[index]}))
const resultArray = Object.entries(promiseResult)
.filter(([_, value]) => value === true) // Only keep entries with a value of true
.map(([key, _]) => {
const [prefix, address, contractName] = key.split('.');
.filter(([_key, value]) => value === true) // Only keep entries with a value of true
.map(([key]) => {
// ignore the prefix
const [, address, contractName] = key.split('.');
return {
address: `0x${address}`,
contract_name: contractName,
contractName: contractName,
};
});

return resultArray;
};

checkNFTListEnabledNew = async (address: string) => {
checkNFTListEnabled = async (address: string): Promise<Record<string, boolean>> => {
// Returns a map of enabled NFTs for the address
const script = await getScripts('nft', 'checkNFTListEnabled');

const isEnabledList = await fcl.query({
Expand All @@ -1496,65 +1492,6 @@ class OpenApiService {
return isEnabledList;
};

checkNFTListEnabled = async (address: string, allTokens: NFTModel[]): Promise<NFTModel[]> => {
const tokens = allTokens;
const tokenImports = tokens
.map((token) =>
'import <Token> from <TokenAddress>'
.replaceAll('<Token>', token.contract_name)
.replaceAll('<TokenAddress>', token.address)
)
.join('\r\n');

const tokenFunctions = tokens
.map((token) =>
`
pub fun check<Token>Vault(address: Address) : Bool {
let account = getAccount(address)

let vaultRef = account
.getCapability<&{NonFungibleToken.CollectionPublic}>(<TokenCollectionPublicPath>)
.check()

return vaultRef
}
`
.replaceAll('<TokenCollectionPublicPath>', token.path.public_path)
.replaceAll('<Token>', token.contract_name)
.replaceAll('<TokenAddress>', token.address)
)
.join('\r\n');

const tokenCalls = tokens
.map((token) =>
`
check<Token>Vault(address: address)
`.replaceAll('<Token>', token.contract_name)
)
.join(',');

const cadence = `
import NonFungibleToken from 0xNonFungibleToken
<TokenImports>

<TokenFunctions>

pub fun main(address: Address) : [Bool] {
return [<TokenCall>]
}
`
.replaceAll('<TokenFunctions>', tokenFunctions)
.replaceAll('<TokenImports>', tokenImports)
.replaceAll('<TokenCall>', tokenCalls);

const enabledList = await fcl.query({
cadence: cadence,
args: (arg, t) => [arg(address, t.Address)],
});

return enabledList;
};

getTransactionTemplate = async (cadence: string, network: string) => {
console.log('getTransactionTemplate ->');
const base64 = Buffer.from(cadence, 'utf8').toString('base64');
Expand Down Expand Up @@ -1827,7 +1764,10 @@ class OpenApiService {
return data;
};

getNFTV2CollectionList = async (address: string, network = 'mainnet') => {
getNFTV2CollectionList = async (
address: string,
network = 'mainnet'
): Promise<NFTModel_depreciated[]> => {
const { data } = await this.sendRequest(
'GET',
`/api/v2/nft/collections?network=${network}&address=${address}`,
Expand Down
Loading
Loading