-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): include Solana in the tokens derived (#3955)
# Motivation We include the Solana tokens in the list of the derived tokens, pinning it among the native ones. # Changes - Create derived tokens list store for Solana. - Add the new store to the current list of tokens. - Include Solana mainnet token among the pinned ones. # Tests Created some tests. But here there is the result. ![Screenshot 2024-12-11 at 20 53 52](https://github.com/user-attachments/assets/b69940dc-7446-429f-8208-f7f5cd933db9) ![Screenshot 2024-12-11 at 20 54 10](https://github.com/user-attachments/assets/18716702-45e2-44c0-8e03-4e4b16879c89) ![Screenshot 2024-12-11 at 20 54 18](https://github.com/user-attachments/assets/5fbd518c-2aa6-4324-ae01-faae60ec5ba3) --------- Co-authored-by: Robert Schlittler <robert.schlittler@inacta.ch>
- Loading branch information
1 parent
f5bd040
commit 54a396a
Showing
4 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SOLANA_NETWORK_ENABLED } from '$env/networks/networks.sol.env'; | ||
import { | ||
SOLANA_DEVNET_TOKEN, | ||
SOLANA_LOCAL_TOKEN, | ||
SOLANA_TESTNET_TOKEN, | ||
SOLANA_TOKEN | ||
} from '$env/tokens/tokens.sol.env'; | ||
import { LOCAL } from '$lib/constants/app.constants'; | ||
import { testnets } from '$lib/derived/testnets.derived'; | ||
import type { Token } from '$lib/types/token'; | ||
import { derived, type Readable } from 'svelte/store'; | ||
|
||
export const enabledSolanaTokens: Readable<Token[]> = derived([testnets], ([$testnets]) => | ||
SOLANA_NETWORK_ENABLED | ||
? [ | ||
SOLANA_TOKEN, | ||
...($testnets | ||
? [SOLANA_TESTNET_TOKEN, SOLANA_DEVNET_TOKEN, ...(LOCAL ? [SOLANA_LOCAL_TOKEN] : [])] | ||
: []) | ||
] | ||
: [] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as solEnv from '$env/networks/networks.sol.env'; | ||
import { | ||
SOLANA_DEVNET_TOKEN, | ||
SOLANA_LOCAL_TOKEN, | ||
SOLANA_TESTNET_TOKEN, | ||
SOLANA_TOKEN | ||
} from '$env/tokens/tokens.sol.env'; | ||
import * as appContants from '$lib/constants/app.constants'; | ||
import { testnetsStore } from '$lib/stores/settings.store'; | ||
import { enabledSolanaTokens } from '$sol/derived/tokens.derived'; | ||
import { get } from 'svelte/store'; | ||
|
||
describe('tokens.derived', () => { | ||
describe('enabledSolanaTokens', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
|
||
testnetsStore.reset({ key: 'testnets' }); | ||
|
||
vi.spyOn(solEnv, 'SOLANA_NETWORK_ENABLED', 'get').mockImplementation(() => true); | ||
}); | ||
|
||
it('should return only mainnet token by default', () => { | ||
expect(get(enabledSolanaTokens)).toEqual([SOLANA_TOKEN]); | ||
}); | ||
|
||
it('should return emtpy array if feature flag false', () => { | ||
vi.spyOn(solEnv, 'SOLANA_NETWORK_ENABLED', 'get').mockImplementation(() => false); | ||
expect(get(enabledSolanaTokens)).toEqual([]); | ||
}); | ||
|
||
it('should return testnet tokens when they are enabled', () => { | ||
testnetsStore.set({ key: 'testnets', value: { enabled: true } }); | ||
vi.spyOn(appContants, 'LOCAL', 'get').mockImplementationOnce(() => false); | ||
|
||
expect(get(enabledSolanaTokens)).toEqual([ | ||
SOLANA_TOKEN, | ||
SOLANA_TESTNET_TOKEN, | ||
SOLANA_DEVNET_TOKEN | ||
]); | ||
}); | ||
|
||
it('should return localnet token when in local env', () => { | ||
testnetsStore.set({ key: 'testnets', value: { enabled: true } }); | ||
vi.spyOn(appContants, 'LOCAL', 'get').mockImplementationOnce(() => true); | ||
|
||
expect(get(enabledSolanaTokens)).toEqual([ | ||
SOLANA_TOKEN, | ||
SOLANA_TESTNET_TOKEN, | ||
SOLANA_DEVNET_TOKEN, | ||
SOLANA_LOCAL_TOKEN | ||
]); | ||
}); | ||
}); | ||
}); |