Skip to content

Commit

Permalink
feat: solana initial structure
Browse files Browse the repository at this point in the history
  • Loading branch information
peronczyk committed Sep 6, 2024
1 parent 92a5aca commit 53d1b4f
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 181 deletions.
2 changes: 1 addition & 1 deletion src/composables/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function useCurrencies({

function getCoinGeckoCoinIdList() {
return protocolsInUse.value.map(
(protocol) => ProtocolAdapterFactory.getAdapter(protocol).getCoinGeckoCoinId(),
(protocol) => ProtocolAdapterFactory.getAdapter(protocol).coinGeckoCoinId,
).join(',');
}

Expand Down
1 change: 1 addition & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const PROTOCOLS = {
aeternity: 'aeternity',
bitcoin: 'bitcoin',
ethereum: 'ethereum',
solana: 'solana',
} as const;

export const PROTOCOL_LIST = Object.values(PROTOCOLS);
Expand Down
13 changes: 3 additions & 10 deletions src/icons/coin/bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
257 changes: 125 additions & 132 deletions src/icons/coin/dogecoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 6 additions & 13 deletions src/icons/coin/ethereum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/icons/coin/solana.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/popup/components/AssetIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { AE_AVATAR_URL } from '@/protocols/aeternity/config';
import AeternityIcon from '@/icons/coin/aeternity.svg?vue-component';
import BitcoinIcon from '@/icons/coin/bitcoin.svg?vue-component';
import EthereumIcon from '@/icons/coin/ethereum.svg?vue-component';
import SolanaIcon from '@/icons/coin/solana.svg?vue-component';
import LexonTokenIcon from '@/icons/tokens/ct_xtk8rSz9suPb6D6VLquyfVji25FcnFRDjn3dnn5mmvHsPiESt.svg?vue-component';
const SIZES = [ICON_SIZES.sm, ICON_SIZES.rg, ICON_SIZES.md, ICON_SIZES.lg, ICON_SIZES.xxl] as const;
Expand All @@ -46,6 +47,7 @@ const COIN_ICONS: Record<Protocol, Component> = {
[PROTOCOLS.aeternity]: AeternityIcon,
[PROTOCOLS.bitcoin]: BitcoinIcon,
[PROTOCOLS.ethereum]: EthereumIcon,
[PROTOCOLS.solana]: SolanaIcon,
};
const ASSET_ICONS: Dictionary<Component> = {
Expand Down
4 changes: 2 additions & 2 deletions src/popup/components/Modals/AccountCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default defineComponent({
setup(props) {
const { addRawAccount, setActiveAccountByGlobalIdx } = useAccounts();
const { isOnline } = useConnection();
const { openModal } = useModals();
const { openModal, openDefaultModal } = useModals();
const { setLoaderVisible } = useUi();
async function createAccount(protocol: Protocol) {
Expand All @@ -82,7 +82,7 @@ export default defineComponent({
break;
default:
throw new Error(`createAccount not implemented for protocol: ${protocol}`);
openDefaultModal({ icon: 'alert', msg: `Account creation not possible for protocol: ${protocol}` });
}
setLoaderVisible(false);
props.resolve();
Expand Down
3 changes: 3 additions & 0 deletions src/popup/components/ProtocolIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
} from 'vue';
import { ICON_SIZES, PROTOCOLS } from '@/constants';
import type { Protocol } from '@/types';
import AeternityLogo from '@/icons/logo/aeternity.svg?vue-component';
import BitcoinIcon from '@/icons/coin/bitcoin.svg?vue-component';
import EthereumIcon from '@/icons/coin/ethereum.svg?vue-component';
import SolanaIcon from '@/icons/coin/solana.svg?vue-component';
const SIZES = [ICON_SIZES.xs, ICON_SIZES.md, ICON_SIZES.rg, ICON_SIZES.lg, ICON_SIZES.xl] as const;
Expand All @@ -41,6 +43,7 @@ export default defineComponent({
[PROTOCOLS.aeternity]: AeternityLogo,
[PROTOCOLS.bitcoin]: BitcoinIcon,
[PROTOCOLS.ethereum]: EthereumIcon,
[PROTOCOLS.solana]: SolanaIcon,
};
const selectedIcon = computed((): Component => iconsMap[props.protocol]);
Expand Down
17 changes: 10 additions & 7 deletions src/popup/components/ProtocolSpecificView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ import {
defineComponent,
ref,
} from 'vue';
import { useRoute, useRouter } from 'vue-router';
import {
onIonViewDidEnter,
onIonViewDidLeave,
onIonViewWillEnter,
onIonViewWillLeave,
} from '@ionic/vue';
import type {
WalletRouteMeta,
Protocol,
Expand All @@ -41,14 +49,8 @@ import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory';
import aeternityViews from '@/protocols/aeternity/views';
import bitcoinViews from '@/protocols/bitcoin/views';
import ethereumViews from '@/protocols/ethereum/views';
import solanaViews from '@/protocols/solana/views';
import { useRoute, useRouter } from 'vue-router';
import {
onIonViewDidEnter,
onIonViewDidLeave,
onIonViewWillEnter,
onIonViewWillLeave,
} from '@ionic/vue';
import InfoBox from './InfoBox.vue';
/**
Expand All @@ -58,6 +60,7 @@ const views: Record<Protocol, ProtocolViewsConfig> = {
aeternity: aeternityViews,
bitcoin: bitcoinViews,
ethereum: ethereumViews,
solana: solanaViews,
};
export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion src/popup/pages/Assets/AssetDetailsInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default defineComponent({
const tokenBalance = computed(() => sharedAssetDetails.tokenBalance);
const isCoin = computed(() => isAssetCoin(assetContractId.value));
const decimals = computed(() => assetData.value?.decimals || tokenBalance.value?.decimals);
const coinGeckoLinkUrl = computed(() => `https://www.coingecko.com/en/coins/${adapter.value.getCoinGeckoCoinId()}`);
const coinGeckoLinkUrl = computed(() => `https://www.coingecko.com/en/coins/${adapter.value.coinGeckoCoinId}`);
const coinGeckoLinkLabel = computed(() => coinGeckoLinkUrl.value.replace('https://', '').replace('en/coins', '...'));
const poolShare = computed(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/BaseProtocolAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export abstract class BaseProtocolAdapter {

abstract coinPrecision: number;

abstract coinGeckoCoinId: string;

/**
* Defines if the protocol supports fungible tokens (token contracts).
*/
Expand All @@ -57,8 +59,6 @@ export abstract class BaseProtocolAdapter {

abstract getUrlTokenKey(): string;

abstract getCoinGeckoCoinId(): string;

abstract getDefaultCoin(
marketData?: MarketData,
convertedBalance?: number | BigNumber,
Expand Down
6 changes: 2 additions & 4 deletions src/protocols/aeternity/libs/AeternityAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export class AeternityAdapter extends BaseProtocolAdapter {

override coinPrecision = AE_COIN_PRECISION;

override coinGeckoCoinId = AE_COINGECKO_COIN_ID;

override hasTokensSupport = true;

override mdwToNodeApproxDelayTime = AE_MDW_TO_NODE_APPROX_DELAY_TIME;
Expand Down Expand Up @@ -128,10 +130,6 @@ export class AeternityAdapter extends BaseProtocolAdapter {
return AE_SYMBOL;
}

override getCoinGeckoCoinId() {
return AE_COINGECKO_COIN_ID;
}

override getDefaultCoin(
marketData?: MarketData,
convertedBalance?: number,
Expand Down
6 changes: 2 additions & 4 deletions src/protocols/bitcoin/libs/BitcoinAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class BitcoinAdapter extends BaseProtocolAdapter {

override coinPrecision = BTC_COIN_PRECISION;

override coinGeckoCoinId = BTC_COINGECKO_COIN_ID;

override hasTokensSupport = false;

override mdwToNodeApproxDelayTime = 0;
Expand Down Expand Up @@ -115,10 +117,6 @@ export class BitcoinAdapter extends BaseProtocolAdapter {
return BTC_NETWORK_DEFAULT_SETTINGS[networkType];
}

override getCoinGeckoCoinId() {
return BTC_COINGECKO_COIN_ID;
}

override getDefaultCoin(
marketData?: MarketData,
convertedBalance?: number,
Expand Down
8 changes: 3 additions & 5 deletions src/protocols/ethereum/libs/EthereumAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class EthereumAdapter extends BaseProtocolAdapter {

override coinPrecision = ETH_COIN_PRECISION;

override coinGeckoCoinId = ETH_COINGECKO_COIN_ID;

override hasTokensSupport = true;

override mdwToNodeApproxDelayTime = ETH_MDW_TO_NODE_APPROX_DELAY_TIME;
Expand Down Expand Up @@ -124,10 +126,6 @@ export class EthereumAdapter extends BaseProtocolAdapter {
return 9;
}

override getCoinGeckoCoinId() {
return ETH_COINGECKO_COIN_ID;
}

override getExplorer() {
const { ethActiveNetworkPredefinedSettings } = useEthNetworkSettings();
return new EtherscanExplorer(ethActiveNetworkPredefinedSettings.value.explorerUrl!);
Expand Down Expand Up @@ -492,7 +490,7 @@ export class EthereumAdapter extends BaseProtocolAdapter {
};
}

async constructAndSignTx(
override async constructAndSignTx(
amount: number,
recipient: string,
options: Record<string, any>,
Expand Down
2 changes: 2 additions & 0 deletions src/protocols/registerAdapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory';
import { AeternityAdapter } from '@/protocols/aeternity/libs/AeternityAdapter';
import { BitcoinAdapter } from '@/protocols/bitcoin/libs/BitcoinAdapter';
import { EthereumAdapter } from '@/protocols/ethereum/libs/EthereumAdapter';
import { SolanaAdapter } from '@/protocols/solana/libs/SolanaAdapter';
import { BaseProtocolAdapter } from './BaseProtocolAdapter';

const protocolAdapters: Record<Protocol, Class<BaseProtocolAdapter>> = {
[PROTOCOLS.aeternity]: AeternityAdapter,
[PROTOCOLS.bitcoin]: BitcoinAdapter,
[PROTOCOLS.ethereum]: EthereumAdapter,
[PROTOCOLS.solana]: SolanaAdapter,
};

Object.entries(protocolAdapters).forEach(([protocol, adapter]) => {
Expand Down
8 changes: 8 additions & 0 deletions src/protocols/solana/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SOL_PROTOCOL_NAME = 'Solana';

export const SOL_CONTRACT_ID = 'solana';

export const SOL_COIN_SYMBOL = 'SOL';
export const SOL_COIN_PRECISION = 18; // Amount of decimals

export const SOL_COINGECKO_COIN_ID = 'solana';
Loading

0 comments on commit 53d1b4f

Please sign in to comment.