Skip to content

Commit

Permalink
show balances for native token, remove sidekick call
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 committed Feb 22, 2024
1 parent caa73ab commit a9a002e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
38 changes: 19 additions & 19 deletions src/plugins/oSnap/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import {
Transaction
} from './types';
import {
allTransactionsValid,
getGnosisSafeBalances,
getGnosisSafeCollectibles,
getIsOsnapEnabled,
getModuleAddressForTreasury,
validateOsnapTransaction
getNativeAsset
} from './utils';
import OsnapMarketingWidget from './components/OsnapMarketingWidget.vue';
Expand Down Expand Up @@ -79,21 +78,20 @@ async function fetchBalances(network: Network, safeAddress: string) {
}
try {
const balances = await getGnosisSafeBalances(network, safeAddress);
const balancesWithNative = balances.map(balance => {
if (!balance.tokenAddress || !balance.token) {
return {
...balance,
token: getNativeAsset(network),
tokenAddress: 'main'
};
}
return balance;
});
const uniswapTokensPromise = fetchTokens(
'https://gateway.ipfs.io/ipns/tokens.uniswap.org'
);
const snapshotTokensPromise = fetchTokens(
`${import.meta.env.VITE_SIDEKICK_URL}/api/moderation?list=verifiedTokens`
);
const tokensLists = await Promise.all([
uniswapTokensPromise,
snapshotTokensPromise
]);
const tokens = tokensLists.flat();
const tokens = await fetchTokens('https://tokens.uniswap.org');
return enhanceTokensWithBalances(balances, tokens);
return enhanceTokensWithBalances(balancesWithNative, tokens, network);
} catch (e) {
console.warn('Error fetching balances');
return [];
Expand All @@ -102,15 +100,16 @@ async function fetchBalances(network: Network, safeAddress: string) {
function enhanceTokensWithBalances(
balances: Partial<BalanceResponse>[],
tokens: Token[]
tokens: Token[],
network: Network
) {
console.log({ balances, tokens });
return balances
.filter(
(balance): balance is BalanceResponse =>
!!balance.token && !!balance.tokenAddress && !!balance.balance
)
.map(balance => enhanceTokenWithBalance(balance, tokens))
.map(balance => enhanceTokenWithBalance(balance, tokens, network))
.sort((a, b) => {
if (a.verified && b.verified) return 0;
if (a.verified) return -1;
Expand All @@ -121,7 +120,8 @@ function enhanceTokensWithBalances(
// gets token balances and also determines if the token is verified
function enhanceTokenWithBalance(
balance: BalanceResponse,
tokens: Token[]
tokens: Token[],
network: Network
): Token {
const verifiedToken = getVerifiedToken(balance.tokenAddress, tokens);
return {
Expand All @@ -131,7 +131,7 @@ function enhanceTokenWithBalance(
? formatUnits(balance.balance, balance.token.decimals)
: '0',
verified: !!verifiedToken,
chainId: verifiedToken ? verifiedToken.chainId : undefined
chainId: network
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const exploreUrl = computed(() => {
</div>

<div class="h-full text-right">
<span v-if="token.address !== 'main'" class="text-skin-link">
<span class="text-skin-link">
{{
formatNumber(
Number(token.balance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const emit = defineEmits<{
updateTransaction: [transaction: TransferFundsTransaction];
}>();
const nativeAsset = getNativeAsset(props.network);
const amount = ref(props.transaction.amount ?? '');
const recipient = ref(props.transaction.recipient ?? '');
const tokens = ref<Token[]>([nativeAsset, ...props.tokens]);
const tokens = ref<Token[]>(props.tokens);
const selectedTokenAddress = ref<Token['address']>(
props.transaction?.token?.address ?? 'main'
Expand All @@ -35,7 +34,8 @@ const selectedTokenAddress = ref<Token['address']>(
const selectedToken = computed(
() =>
tokens.value.find(token => token.address === selectedTokenAddress.value) ??
nativeAsset
tokens.value.find(token => !token.address) ??
tokens.value[0]
);
const isTokenModalOpen = ref(false);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/oSnap/utils/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function callGnosisSafeTransactionApi<TResult = any>(
*/
export const getGnosisSafeBalances = memoize(
(network: Network, safeAddress: string) => {
const endpointPath = `/v1/safes/${safeAddress}/balances/`;
const endpointPath = `/v1/safes/${safeAddress}/balances?exclude_spam=true`;
return callGnosisSafeTransactionApi<Partial<BalanceResponse>[]>(
network,
endpointPath
Expand Down

0 comments on commit a9a002e

Please sign in to comment.