Skip to content

Commit

Permalink
use indexer lookup for futurenet token (#1217) (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
piyalbasu authored Mar 28, 2024
1 parent da2f062 commit 48d1701
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions extension/src/popup/components/manageAssets/AddToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,33 @@ export const AddToken = () => {
return;
}

const indexerLookup = async () => {
// lookup contract
setIsVerifiedToken(false);
const tokenUrl = new URL(`${INDEXER_URL}/token-details/${contractId}`);
tokenUrl.searchParams.append("network", networkDetails.network);
tokenUrl.searchParams.append("pub_key", publicKey);
tokenUrl.searchParams.append(
"soroban_url",
networkDetails.sorobanRpcUrl!,
);

const res = await fetch(tokenUrl.href);
const resJson = await res.json();
if (!res.ok) {
throw new Error(JSON.stringify(resJson));
} else {
setAssetRows([
{
code: resJson.symbol,
issuer: contractId,
domain: "",
name: resJson.name,
},
]);
}
};

if (isAllowListVerificationEnabled) {
// usual binary case of a token being verified or unverified
verifiedTokens = await getVerifiedTokens({
Expand All @@ -192,32 +219,8 @@ export const AddToken = () => {
})),
);
} else {
// lookup contract
setIsVerifiedToken(false);
const tokenUrl = new URL(
`${INDEXER_URL}/token-details/${contractId}`,
);
tokenUrl.searchParams.append("network", networkDetails.network);
tokenUrl.searchParams.append("pub_key", publicKey);
tokenUrl.searchParams.append(
"soroban_url",
networkDetails.sorobanRpcUrl!,
);

const res = await fetch(tokenUrl.href);
const resJson = await res.json();
if (!res.ok) {
throw new Error(JSON.stringify(resJson));
} else {
setAssetRows([
{
code: resJson.symbol,
issuer: contractId,
domain: "",
name: resJson.name,
},
]);
}
// token not found on asset list, look up the details manually
await indexerLookup();
}
} catch (e) {
setAssetRows([]);
Expand All @@ -226,6 +229,9 @@ export const AddToken = () => {
);
console.error(e);
}
} else {
// Futurenet token lookup
await indexerLookup();
}

setIsVerificationInfoShowing(isAllowListVerificationEnabled);
Expand Down

0 comments on commit 48d1701

Please sign in to comment.