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

[support] Algo assets are not searchable/selectable on the bridge, user id -736691227193245717 #1045

Merged
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
58 changes: 25 additions & 33 deletions src/components/TokenSelectors/AlgoTokenPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,36 @@ export default function AlgoTokenPicker(props: AlgoTokenPickerProps) {
);

const lookupAlgoAddress = useCallback(
(lookupAsset: string) => {
if (!walletAddress) {
return Promise.reject("Wallet not connected");
}
async (lookupAsset: string) => {
if (!walletAddress) throw new Error("Wallet not connected");
const algodClient = new Algodv2(
ALGORAND_HOST.algodToken,
ALGORAND_HOST.algodServer,
ALGORAND_HOST.algodPort
);
return fetchSingleMetadata(lookupAsset, algodClient)
.then((metadata) => {
return algodClient
.accountInformation(walletAddress)
.do()
.then((accountInfo) => {
for (const asset of accountInfo.assets) {
const assetId = asset["asset-id"];
if (assetId.toString() === lookupAsset) {
const amount = asset.amount;
return createParsedTokenAccount(
walletAddress,
assetId.toString(),
amount,
metadata.decimals,
parseFloat(formatUnits(amount, metadata.decimals)),
formatUnits(amount, metadata.decimals).toString(),
metadata.symbol,
metadata.tokenName,
undefined,
false
);
}
}
return Promise.reject();
})
.catch(() => Promise.reject());
})
.catch(() => Promise.reject());
const metadata = await fetchSingleMetadata(lookupAsset, algodClient);
const accountInfo = await algodClient
.accountInformation(walletAddress)
.do();

const asset = accountInfo.assets.find(
(asset: any) => asset["asset-id"]?.toString() === lookupAsset
);

if (!asset) throw new Error("Asset not found");

return createParsedTokenAccount(
walletAddress,
asset["asset-id"]?.toString(),
asset.amount,
metadata.decimals,
parseFloat(formatUnits(asset.amount, metadata.decimals)),
formatUnits(asset.amount, metadata.decimals).toString(),
metadata.symbol,
metadata.tokenName,
undefined,
false
);
},
[walletAddress]
);
Expand Down
82 changes: 48 additions & 34 deletions src/components/TokenSelectors/TokenPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,31 +305,40 @@ export default function TokenPicker({
const handleSelectOption = useCallback(
async (option: NFTParsedTokenAccount) => {
setSelectionError("");
let newOption = null;
try {
//Covalent balances tend to be stale, so we make an attempt to correct it at selection time.
if (getAddress && !option.isNativeAsset) {
newOption = await getAddress(option.mintKey, option.tokenId);
newOption = {
...option,
...newOption,
// keep logo and uri from covalent / market list / etc (otherwise would be overwritten by undefined)
logo: option.logo || newOption.logo,
uri: option.uri || newOption.uri,
} as NFTParsedTokenAccount;
} else {
newOption = option;
}
await onChange(newOption);
// covalent balances tend to be stale, so we make an attempt to correct it at selection time.
const updatedOption: Partial<NFTParsedTokenAccount> =
typeof getAddress === "function" && !option.isNativeAsset
? await (async () => {
try {
const response = await getAddress(
option.mintKey,
option.tokenId
);
return response;
} catch (error: any) {
// using stale value when updated value can't be found
if (error?.message === "Asset not found") return option;
throw error;
}
})()
: {};

await onChange({
...option,
...updatedOption,
// keep logo and uri from covalent / market list / etc (otherwise would be overwritten by undefined)
logo: option.logo || updatedOption?.logo,
uri: option.uri || updatedOption?.uri,
} as NFTParsedTokenAccount);
closeDialog();
} catch (e: any) {
if (e.message?.includes("v1")) {
setSelectionError(e.message);
} else {
setSelectionError(
"Unable to retrieve required information about this token. Ensure your wallet is connected, then refresh the list."
);
}
console.error(e);
setSelectionError(
e?.message?.includes("v1")
? e.message
: "Unable to retrieve required information about this token. Ensure your wallet is connected, then refresh the list."
);
}
},
[getAddress, onChange, closeDialog]
Expand All @@ -347,17 +356,18 @@ export default function TokenPicker({
if (!holderString) {
return true;
}
const optionString = (
(option.publicKey || "") +
" " +
(option.mintKey || "") +
" " +
(option.symbol || "") +
" " +
(option.name || " ")
).toLowerCase();
const searchString = holderString.toLowerCase();
return optionString.includes(searchString);

const optionString = [
option.publicKey,
option.mintKey,
option.symbol,
option.name,
]
.filter(Boolean)
.join(" ")
.toLowerCase();

return optionString.includes(holderString.toLowerCase());
},
[holderString]
);
Expand Down Expand Up @@ -465,7 +475,11 @@ export default function TokenPicker({
(error) => {
if (!cancelled) {
setLocalLoading(false);
setLoadingError("Could not find the specified address.");
console.error(error);
// leaving default "no results"
if (error?.message !== "Asset not found") {
setLoadingError("Could not find the specified address.");
}
}
}
);
Expand Down
Loading