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

fixed: display linked account nft in settings frontend #189

Merged
merged 4 commits into from
Nov 20, 2024
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
4 changes: 4 additions & 0 deletions src/ui/views/Dashboard/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ const Header = ({ loading }) => {
evmWallet.address = evmAddress;
await setCurrent(evmWallet);
setMainLoading(false);
} else if (isChild) {
const currentWallet = await usewallet.getCurrentWallet();
await setCurrent(currentWallet);
setMainLoading(false);
} else {
const mainwallet = await usewallet.returnMainWallet();
await setCurrent(mainwallet);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/views/Setting/Linked/LinkedCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const LinkedCollection = (props) => {
try {
const res = await getCollection(address, collection_name);
console.log('res ', res);
setInfo(res.info);
setInfo(res.collection);
setTotal(res.nftCount);
setLists(res.nfts);
} catch (err) {
Expand Down Expand Up @@ -245,7 +245,6 @@ const LinkedCollection = (props) => {
};

const getCollection = async (ownerAddress, collection, offset = 0) => {
console.log('collection_info ', collection_info);
return await usewallet.getSingleCollection(ownerAddress, collection, offset);
};

Expand Down Expand Up @@ -314,7 +313,7 @@ const LinkedCollection = (props) => {
</Grid>
<Grid item sx={{ ml: 0, pl: '18px' }}>
<Typography component="div" color="text.primary" variant="h6">
{truncate(info?.collectionDisplay?.name || info.name, 16)}
{truncate(info?.name || info.contract_name, 16)}
</Typography>

<Tooltip title={chrome.i18n.getMessage('Refresh')} arrow>
Expand Down
30 changes: 11 additions & 19 deletions src/ui/views/Setting/Linked/LinkedDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const LinkedDetail = () => {
setChildAccount(childresp[key]);
setKey(key);
const catalog = await usewallet.getNftCatalog();
console.log('catalog ,', catalog);

const parentaddress = await usewallet.getMainWallet();

Expand All @@ -118,25 +117,18 @@ const LinkedDetail = () => {

const nftResult = await usewallet.checkAccessibleNft(parentaddress);
activec.forEach((active) => {
console.log('nft result ', active);
const collection = findObjectByContractName(active, catalog);
if (collection) {
collectionMap[collection.contract_name] = { ...collection, total: 0, nfts: [] };
}
});
console.log('nft result ', nftResult, key);

nftResult.forEach((nft) => {
const someResult = checkContractAddressInCollections(nft, Object.values(collectionMap));
console.log('someResult , ', someResult, Object.values(collectionMap));
Object.entries(nftResult[key]).forEach((nft) => {
const someResult = checkContractAddressInCollections(nft[0], Object.values(collectionMap));
if (someResult) {
collectionMap[someResult.contract_name].total! += 1;
collectionMap[someResult.contract_name].nfts!.push(nft);
}
});
console.log('collectionMap result ', collectionMap);

console.log('active check nftResult ', nftResult);
if (nftResult) {
setNft(nftResult);
const collectionsArray = Object.values(collectionMap);
Expand All @@ -148,29 +140,29 @@ const LinkedDetail = () => {
}

setLoading(false);
console.log('availableNft ', availableNft, availableFt);
} catch (error) {
// Handle any errors that occur during data fetching
console.error('Error fetching data:', error);
setLoading(false);
}
};

const extractContractAddress = (collection) => {
const extractContractName = (collection) => {
return collection.split('.')[2];
};

const findObjectByContractName = (contractName, collections) => {
const extractedAddress = extractContractAddress(contractName);
const foundObject = collections.find((item) => item.contract_name === extractedAddress);
const extractedContract = extractContractName(contractName);
const foundObject = collections.find((item) => item.contract_name === extractedContract);
return foundObject || null;
};

const checkContractAddressInCollections = (nft, activec) => {
const contractAddressWithout0x = nft.collectionName;
const matchedResult = activec.find((collection) => {
const extractedAddress = collection.name;
return extractedAddress === contractAddressWithout0x;
const parts = nft.split('.');
const address = `0x${parts[1]}`;
const contractName = parts[2];
return collection.address === address && collection.contract_name == contractName;
});
return matchedResult;
};
Expand All @@ -192,17 +184,17 @@ const LinkedDetail = () => {

const toggleHide = (event) => {
event.stopPropagation();
console.log('hideEmpty ', hideEmpty);
const prevEmpty = hideEmpty;
setHide(!prevEmpty);
};

const navigateWithState = (data, key) => {
const state = { nft: data };
localStorage.setItem('nftLinkedState', JSON.stringify(state));
const storagePath = data.path.storage_path.split('/')[2];
if (data.total) {
history.push({
pathname: `/dashboard/nested/linked/collectiondetail/${key + '.' + data.contract_name + '.' + data.total + '.linked'}`,
pathname: `/dashboard/nested/linked/collectiondetail/${key + '.' + storagePath + '.' + data.total + '.linked'}`,
state: {
collection: data,
ownerAddress: key,
Expand Down