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

devop: switch solana asset handler to helius #578

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div class="send-alert">
<alert-icon />
<p v-if="belowDust">Minimum amount: {{ dust }}</p>
<p v-if="isBalanceZero">Not enough balance.</p>
<p v-else-if="belowDust">Minimum amount: {{ dust }}</p>
<p v-else-if="notEnough">
Not enough funds. You are<br />~{{
$filters.formatFloatingPointValue(nativeValue).value
Expand All @@ -24,6 +25,7 @@ interface IProps {
price?: string;
notEnough: boolean;
belowDust: boolean;
isBalanceZero: boolean;
dust: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"
:native-symbol="network.name"
:price="selectedAsset.price || '0'"
:is-balance-zero="UTXOBalance.isZero()"
:native-value="
fromBase(
nativeBalanceAfterTransaction.abs().toString(),
Expand Down Expand Up @@ -313,8 +314,8 @@ const isInputsValid = computed<boolean>(() => {
)
return false;

const sendAmountBigNumber = new BigNumber(sendAmount.value)
if (sendAmountBigNumber.isNaN()) return false
const sendAmountBigNumber = new BigNumber(sendAmount.value);
if (sendAmountBigNumber.isNaN()) return false;
if (sendAmountBigNumber.gt(assetMaxValue.value)) return false;
return true;
});
Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/providers/ethereum/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class API implements ProviderAPIInterface {
name: 'Unknown',
symbol: 'UNKNWN',
decimals: 18,
icon: undefined,
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export default (
(obj, cur) => ({ ...obj, [cur.contract]: cur }),
{},
);

const marketData = new MarketData();

const marketInfo = supportedNetworks[networkName].cgPlatform
Expand Down Expand Up @@ -336,7 +335,10 @@ export default (
balancef: formatFloatingPointValue(userBalance).value,
balanceUSD: 0,
balanceUSDf: formatFiatValue('0').value,
icon: tokenInfo[unknownTokens[idx]]?.logoURI || network.icon,
icon:
tokenInfo[unknownTokens[idx]]?.logoURI ||
tInfo.icon ||
network.icon,
name: tInfo.name,
symbol: tInfo.symbol,
value: '0',
Expand All @@ -350,7 +352,6 @@ export default (
});
});
}

return assets;
});
};
1 change: 1 addition & 0 deletions packages/extension/src/providers/ethereum/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface ERC20TokenInfo {
name: string;
symbol: string;
decimals: number;
icon?: string;
}
export interface JsonRpcRequest {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ const errorMsg = computed(() => {
}

if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) {
return `Amount exceeds maximum value.`;
return `Not enough balance.`;
}

return '';
Expand Down Expand Up @@ -562,8 +562,8 @@ const isInputsValid = computed<boolean>(() => {
if (!isSendToken.value && !selectedNft.value.id) {
return false;
}
const sendAmountBigNumber = new BigNumber(sendAmount.value)
if (sendAmountBigNumber.isNaN()) return false
const sendAmountBigNumber = new BigNumber(sendAmount.value);
if (sendAmountBigNumber.isNaN()) return false;
if (sendAmountBigNumber.gt(assetMaxValue.value)) return false;
if (gasCostValues.value.REGULAR.nativeValue === '0') return false;
if (!isNumericPositive(sendAmount.value)) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ const validateFields = async () => {

if (rawAmount.add(rawFee).gt(rawBalance)) {
fieldsValidation.value.amount = false;
errorMsg.value = 'Insufficient funds';
errorMsg.value = 'Not enough balance.';
return;
}

Expand Down
65 changes: 36 additions & 29 deletions packages/extension/src/providers/solana/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class API implements ProviderAPIInterface {
return getSolAddress(pubkey);
}

async init(): Promise<void> { }
async init(): Promise<void> {}

/**
* Returns null if the transaction hasn't been received by the node
Expand All @@ -33,7 +33,7 @@ class API implements ProviderAPIInterface {
const tx = await this.web3.getTransaction(hash, {
maxSupportedTransactionVersion: 0,
commitment: 'confirmed',
})
});

if (!tx) {
// Transaction hasn't been picked up by the node
Expand Down Expand Up @@ -66,39 +66,47 @@ class API implements ProviderAPIInterface {
}

getTokenInfo = async (contractAddress: string): Promise<SPLTokenInfo> => {
interface TokenDetails {
address: string;
decimals: number;
name: string;
symbol: string;
logoURI: string;
extensions?: { coingeckoId: string };
}
const allTokensResponse = await cacheFetch(
const tokenResponse: {
result?: {
token_info: {
symbol: string;
decimals: number;
};
content: {
files: { uri: string }[];
metadata: {
name: string;
symbol: string;
};
};
};
} = await cacheFetch(
{
url: 'https://raw.githubusercontent.com/solflare-wallet/token-list/refs/heads/master/solana-tokenlist.json',
postProcess: (data: any) => {
const allTokens = data.tokens as TokenDetails[];
const tObj: Record<string, TokenDetails> = {};
allTokens.forEach(t => {
tObj[t.address] = t;
});
return tObj;
url: this.node,
post: {
jsonrpc: '2.0',
id: 1,
method: 'getAsset',
params: {
id: contractAddress,
},
},
},
6 * 60 * 60 * 1000,
);
const allTokens = allTokensResponse as Record<string, TokenDetails>;
let decimals = 9;
kvhnuke marked this conversation as resolved.
Show resolved Hide resolved
if (allTokens[contractAddress]) {
if (tokenResponse.result) {
return {
name: allTokens[contractAddress].name,
symbol: allTokens[contractAddress].symbol,
decimals: allTokens[contractAddress].decimals,
icon: allTokens[contractAddress].logoURI,
cgId: allTokens[contractAddress].extensions?.coingeckoId
? allTokens[contractAddress].extensions?.coingeckoId
: undefined,
name: tokenResponse.result.content.metadata.name
? tokenResponse.result.content.metadata.name
: tokenResponse.result.content.metadata.symbol,
symbol: tokenResponse.result.content.metadata.symbol,
decimals: tokenResponse.result.token_info.decimals,
icon:
tokenResponse.result.content.files &&
tokenResponse.result.content.files.length > 0
? `https://img.mewapi.io/?image=${tokenResponse.result.content.files[0].uri}`
: undefined,
};
} else {
await this.web3
Expand All @@ -115,7 +123,6 @@ class API implements ProviderAPIInterface {
symbol: 'UNKNWN',
decimals,
icon: undefined,
cgId: undefined,
};
};
}
Expand Down
4 changes: 1 addition & 3 deletions packages/extension/src/providers/solana/types/sol-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import SolanaAPI from '@/providers/bitcoin/libs/api';
import { ERC20TokenInfo } from '@/providers/ethereum/types';

export interface SPLTokenInfo extends ERC20TokenInfo {
icon: string | undefined;
cgId: string | undefined;
cgId?: string;
}

export interface SolTokenOptions extends BaseTokenOptions {
contract: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ const errorMsg = computed(() => {
}

if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) {
return `Amount exceeds maximum value.`;
return `Not enough balance.`;
}

return '';
Expand Down
Loading