Skip to content

Commit

Permalink
Merge branch 'main' into feat(frontend)/add-AAA-ICRC-token
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioVentilii authored Jan 22, 2025
2 parents dd32718 + 6fbb250 commit 88ba230
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-to-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:
echo "NETWORK=staging" >> $GITHUB_ENV
elif [ "${{ github.ref_type }}" == "tag" ]; then
echo "NETWORK=beta" >> $GITHUB_ENV
elif [ "${{ github.ref_type }}" == "workflow_run" ]; then
echo "NETWORK=beta" >> $GITHUB_ENV
else
echo "Error: Unsupported ref type."
exit 1
Expand All @@ -70,6 +68,8 @@ jobs:
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "NETWORK=${{ github.event.inputs.network }}" >> $GITHUB_ENV
echo "CANISTER=${{ github.event.inputs.canister }}" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" == "workflow_run" ]; then
echo "NETWORK=beta" >> $GITHUB_ENV
else
echo "Error: Unsupported event type."
exit 1
Expand Down
8 changes: 7 additions & 1 deletion src/frontend/src/sol/components/tokens/SolTokenMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
isNetworkIdSOLTestnet
} from '$lib/utils/network.utils';
import type { SolanaNetwork } from '$sol/types/network';
import { isTokenSpl } from '$sol/utils/spl.utils';
let explorerUrl: string | undefined;
$: explorerUrl = ($token?.network as SolanaNetwork)?.explorerUrl;
Expand All @@ -32,9 +33,14 @@
? $solAddressLocal
: $solAddressMainnet;
let tokenAddress: string | undefined;
$: tokenAddress = nonNullish($token) && isTokenSpl($token) ? $token.address : undefined;
let explorerAddressUrl: string | undefined;
$: explorerAddressUrl = nonNullish(explorerUrl)
? replacePlaceholders(explorerUrl, { $args: `account/${address}/` })
? replacePlaceholders(explorerUrl, {
$args: nonNullish(tokenAddress) ? `token/${tokenAddress}/` : `account/${address}/`
})
: undefined;
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SOLANA_MAINNET_NETWORK,
SOLANA_TESTNET_NETWORK
} from '$env/networks/networks.sol.env';
import { TRUMP_TOKEN } from '$env/tokens/tokens-spl/tokens.trump.env';
import {
SOLANA_DEVNET_TOKEN,
SOLANA_TESTNET_TOKEN,
Expand All @@ -28,6 +29,7 @@ import { testnetsStore } from '$lib/stores/settings.store';
import { token as tokenStore } from '$lib/stores/token.store';
import { replacePlaceholders } from '$lib/utils/i18n.utils';
import SolTokenMenu from '$sol/components/tokens/SolTokenMenu.svelte';
import type { SolanaNetwork } from '$sol/types/network';
import { mockPage } from '$tests/mocks/page.store.mock';
import { mockSolAddress } from '$tests/mocks/sol.mock';
import { render, waitFor } from '@testing-library/svelte';
Expand All @@ -45,6 +47,11 @@ describe('SolTokenMenu', () => {
solAddressMainnetStore.reset();
solAddressTestnetStore.reset();
solAddressDevnetStore.reset();

// In component TOkenMenu there is a dependency to the store erc20UserTokensStore that impedes the correct rendering of the component
// So we need to reset the store before each test
// TODO: verify if this dependency can be removed
erc20UserTokensStore.resetAll();
});

const testCases = [
Expand Down Expand Up @@ -75,7 +82,6 @@ describe('SolTokenMenu', () => {
'external link forwards to correct $description explorer',
async ({ token, explorerUrl, network, store }) => {
tokenStore.set(token);
erc20UserTokensStore.reset(token.id);
store.set({ certified: true, data: mockSolAddress });
mockPage.mock({ network: network.id.description });

Expand All @@ -92,4 +98,25 @@ describe('SolTokenMenu', () => {
});
}
);

it('external link forwards to SPL explorer URL', async () => {
const mockToken = TRUMP_TOKEN;

tokenStore.set(mockToken);
mockPage.mock({ network: mockToken.network.id.description });

const { queryByTestId, getByTestId } = render(SolTokenMenu);
const button = getByTestId(TOKEN_MENU_SOL_BUTTON);
button.click();

await waitFor(() => {
const a = queryByTestId(TOKEN_MENU_SOL_EXPLORER_LINK);
expect(a).not.toBeNull();
expect((a as HTMLAnchorElement).href).toEqual(
replacePlaceholders((mockToken.network as SolanaNetwork).explorerUrl ?? '', {
$args: `token/${mockToken.address}/`
})
);
});
});
});

0 comments on commit 88ba230

Please sign in to comment.