Skip to content

Commit

Permalink
feat(suite-native): enable Solana via feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Oct 25, 2024
1 parent b02a26b commit 56c67f9
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 22 deletions.
5 changes: 5 additions & 0 deletions suite-common/graph/src/balanceHistoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ export const getAccountHistoryMovementFromTransactions = ({
case 'pol':
case 'bnb':
return getAccountHistoryMovementItemETH({ transactions, from, to });
case 'sol':
return {
main: [] as AccountHistoryMovementItem[],
tokens: {},
} as AccountHistoryMovement;
default:
coin satisfies never;
throw new Error(`getAccountHistoryMovementItem: Unsupported network ${coin}`);
Expand Down
1 change: 1 addition & 0 deletions suite-common/graph/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const LOCAL_BALANCE_HISTORY_COINS = [
'pol',
'bnb',
'xrp',
'sol',
] satisfies Array<NetworkSymbol>;
export type LocalBalanceHistoryCoin = (typeof LOCAL_BALANCE_HISTORY_COINS)[number];

Expand Down
8 changes: 8 additions & 0 deletions suite-native/app/globalPolyfills.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import * as Crypto from 'expo-crypto';

if (typeof global.crypto !== 'object') {
global.crypto = {};
}
// crypto.getRandomValues polyfill is needed for Solana
global.crypto.getRandomValues = Crypto.getRandomValues;

global.Buffer = require('buffer').Buffer;

global.process = {
Expand Down
1 change: 1 addition & 0 deletions suite-native/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"expo-build-properties": "0.12.5",
"expo-camera": "15.0.15",
"expo-clipboard": "6.0.3",
"expo-crypto": "13.0.2",
"expo-dev-client": "4.0.25",
"expo-haptics": "13.0.1",
"expo-image": "1.12.15",
Expand Down
52 changes: 32 additions & 20 deletions suite-native/discovery/src/discoveryConfigSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,31 @@ export const selectAreTestnetsEnabled = (state: DiscoveryConfigSliceRootState) =
export const selectDiscoveryInfo = (state: DiscoveryConfigSliceRootState) =>
state.discoveryConfig.discoveryInfo;

export const selectFeatureFlagEnabledNetworkSymbols = memoize((state: FeatureFlagsRootState) => {
const isPolygonEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsPolygonEnabled);
const isBscEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsBscEnabled);

const allowlist: NetworkSymbol[] = [];

if (isPolygonEnabled) {
allowlist.push('pol');
}
if (isBscEnabled) {
allowlist.push('bnb');
}
export const selectFeatureFlagEnabledNetworkSymbols = memoize(
(state: FeatureFlagsRootState & DiscoveryConfigSliceRootState) => {
const isPolygonEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsPolygonEnabled);
const isBscEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsBscEnabled);
const isSolanaEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsSolanaEnabled);
const areTestnetsEnabled = selectAreTestnetsEnabled(state);

const allowlist: NetworkSymbol[] = [];

if (isPolygonEnabled) {
allowlist.push('pol');
}
if (isBscEnabled) {
allowlist.push('bnb');
}
if (isSolanaEnabled) {
allowlist.push('sol');
if (areTestnetsEnabled) {
allowlist.push('dsol');
}
}

return allowlist;
});
return allowlist;
},
);

export const selectDiscoverySupportedNetworks = memoizeWithArgs(
(
Expand Down Expand Up @@ -137,7 +147,7 @@ export const selectDiscoveryNetworkSymbols = memoizeWithArgs(
);

export const selectPortfolioTrackerMainnetNetworkSymbols = memoize(
(state: FeatureFlagsRootState) => {
(state: FeatureFlagsRootState & DiscoveryConfigSliceRootState) => {
const allowlist = selectFeatureFlagEnabledNetworkSymbols(state);

return [...portfolioTrackerMainnets, ...allowlist];
Expand All @@ -154,12 +164,14 @@ export const selectPortfolioTrackerTestnetNetworkSymbols = memoize(
},
);

export const selectPortfolioTrackerNetworkSymbols = memoize((state: FeatureFlagsRootState) => {
const mainnets = selectPortfolioTrackerMainnetNetworkSymbols(state);
const testnets = selectPortfolioTrackerTestnetNetworkSymbols(state);
export const selectPortfolioTrackerNetworkSymbols = memoize(
(state: FeatureFlagsRootState & DiscoveryConfigSliceRootState) => {
const mainnets = selectPortfolioTrackerMainnetNetworkSymbols(state);
const testnets = selectPortfolioTrackerTestnetNetworkSymbols(state);

return [...mainnets, ...testnets];
});
return [...mainnets, ...testnets];
},
);

export const selectIsCoinEnablingInitFinished = (
state: DiscoveryConfigSliceRootState & FeatureFlagsRootState,
Expand Down
3 changes: 3 additions & 0 deletions suite-native/feature-flags/src/featureFlagsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const FeatureFlag = {
IsRegtestEnabled: 'isRegtestEnabled',
IsPolygonEnabled: 'IsPolygonEnabled',
IsBscEnabled: 'IsBscEnabled',
IsSolanaEnabled: 'IsSolanaEnabled',
IsConnectPopupEnabled: 'IsConnectPopupEnabled',
} as const;
export type FeatureFlag = (typeof FeatureFlag)[keyof typeof FeatureFlag];
Expand All @@ -27,6 +28,7 @@ export const featureFlagsInitialState: FeatureFlagsState = {
[FeatureFlag.IsRegtestEnabled]: isDebugEnv() || isDetoxTestBuild(),
[FeatureFlag.IsPolygonEnabled]: false,
[FeatureFlag.IsBscEnabled]: false,
[FeatureFlag.IsSolanaEnabled]: false,
[FeatureFlag.IsConnectPopupEnabled]: isDevelopOrDebugEnv(),
};

Expand All @@ -37,6 +39,7 @@ export const featureFlagsPersistedKeys: Array<keyof FeatureFlagsState> = [
FeatureFlag.IsRegtestEnabled,
FeatureFlag.IsPolygonEnabled,
FeatureFlag.IsBscEnabled,
FeatureFlag.IsSolanaEnabled,
FeatureFlag.IsConnectPopupEnabled,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const devXpubs: Partial<Record<NetworkSymbol, string | DevXpub[]>> = {
ada: '432505dc5010ec888c650319035dff62f964002f02473fa7fd65dd67f9bd80b327674cabf29c39a14c367dbae5ee01f967f8b4c3ad63a45468da8f28bb2e03d5',
txrp: 'rJX2KwzaLJDyFhhtXKi3htaLfaUH2tptEX',
xrp: 'r9TCDt3HmszcsnPrUrnvpynvLgaGQom9x3',
sol: 'C4pFbTQGpEXmsmiToPPL2Qix1UDeD8bHXpi77Hk9WesZ',
};

type DevXpub = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const useAddCoinAccount = () => {
availableTypes.set(symbol as NetworkSymbol, [
NORMAL_ACCOUNT_TYPE,
// For Cardano and EVMs allow only normal account type
...(['ada', 'eth', 'pol', 'bnb'].includes(symbol) ? [] : types),
...(['ada', 'eth', 'pol', 'bnb', 'sol'].includes(symbol) ? [] : types),
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const featureFlagsTitleMap = {
[FeatureFlagEnum.IsRegtestEnabled]: 'Regtest',
[FeatureFlagEnum.IsPolygonEnabled]: 'Polygon',
[FeatureFlagEnum.IsBscEnabled]: 'BNB Smart Chain',
[FeatureFlagEnum.IsSolanaEnabled]: 'Solana',
[FeatureFlagEnum.IsConnectPopupEnabled]: 'Connect Popup',
} as const satisfies Record<FeatureFlagEnum, string>;

Expand Down
7 changes: 6 additions & 1 deletion suite-native/tokens/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export const getTokenName = (tokenName?: string) => {
return tokenName;
};

export const NETWORK_SYMBOLS_WITH_TOKENS = ['eth', 'pol', 'bnb'] satisfies Array<NetworkSymbol>;
export const NETWORK_SYMBOLS_WITH_TOKENS = [
'eth',
'pol',
'bnb',
'sol',
] satisfies Array<NetworkSymbol>;
export type NetworkSymbolWithTokens = (typeof NETWORK_SYMBOLS_WITH_TOKENS)[number];

export const isCoinWithTokens = (symbol: NetworkSymbol): symbol is NetworkSymbolWithTokens =>
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9672,6 +9672,7 @@ __metadata:
expo-build-properties: "npm:0.12.5"
expo-camera: "npm:15.0.15"
expo-clipboard: "npm:6.0.3"
expo-crypto: "npm:13.0.2"
expo-dev-client: "npm:4.0.25"
expo-haptics: "npm:13.0.1"
expo-image: "npm:1.12.15"
Expand Down

0 comments on commit 56c67f9

Please sign in to comment.