Skip to content

Commit

Permalink
chore: remove experimental wallets from widget config
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder authored and yeager-eren committed Jan 27, 2025
1 parent 451048d commit 285f88b
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 82 deletions.
37 changes: 14 additions & 23 deletions wallets/react/src/hub/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,25 @@ import { LastConnectedWalletsFromStorage } from './lastConnectedWallets.js';

/* Gets a list of hub and legacy providers and returns a tuple which separates them. */
export function separateLegacyAndHubProviders(
providers: VersionedProviders[],
options?: { isExperimentalEnabled?: boolean }
providers: VersionedProviders[]
): [LegacyProviderInterface[], Provider[]] {
const LEGACY_VERSION = '0.0.0';
const HUB_VERSION = '1.0.0';
const { isExperimentalEnabled = false } = options || {};

if (isExperimentalEnabled) {
const legacyProviders: LegacyProviderInterface[] = [];
const hubProviders: Provider[] = [];

providers.forEach((provider) => {
try {
const target = pickVersion(provider, HUB_VERSION);
hubProviders.push(target[1]);
} catch {
const target = pickVersion(provider, LEGACY_VERSION);
legacyProviders.push(target[1]);
}
});

return [legacyProviders, hubProviders];
}
const legacyProviders: LegacyProviderInterface[] = [];
const hubProviders: Provider[] = [];

providers.forEach((provider) => {
try {
const target = pickVersion(provider, HUB_VERSION);
hubProviders.push(target[1]);
} catch {
const target = pickVersion(provider, LEGACY_VERSION);
legacyProviders.push(target[1]);
}
});

const legacyProviders = providers.map(
(provider) => pickVersion(provider, LEGACY_VERSION)[1]
);
return [legacyProviders, []];
return [legacyProviders, hubProviders];
}

export function findProviderByType(
Expand Down
1 change: 0 additions & 1 deletion wallets/react/src/legacy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export type ProviderProps = PropsWithChildren<{
autoConnect?: boolean;
providers: VersionedProviders[];
configs?: {
isExperimentalEnabled?: boolean;
wallets?: (WalletType | LegacyProviderInterface)[];
};
}>;
Expand Down
8 changes: 2 additions & 6 deletions wallets/react/src/useProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ import { useLegacyProviders } from './legacy/mod.js';
*/
function useProviders(props: ProviderProps) {
const { providers, ...restProps } = props;
const [legacyProviders, hubProviders] = separateLegacyAndHubProviders(
providers,
{
isExperimentalEnabled: restProps.configs?.isExperimentalEnabled,
}
);
const [legacyProviders, hubProviders] =
separateLegacyAndHubProviders(providers);

const legacyApi = useLegacyProviders({
...restProps,
Expand Down
6 changes: 0 additions & 6 deletions widget/embedded/src/containers/Wallets/Wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import React, { createContext, useEffect, useMemo, useRef } from 'react';
import { useWalletProviders } from '../../hooks/useWalletProviders';
import { AppStoreProvider, useAppStore } from '../../store/AppStore';
import { useUiStore } from '../../store/ui';
import { isFeatureEnabled } from '../../utils/settings';
import {
prepareAccountsForWalletStore,
walletAndSupportedChainsNames,
Expand Down Expand Up @@ -54,7 +53,6 @@ function Main(props: PropsWithChildren<PropTypes>) {
walletConnectListedDesktopWalletLink:
props.config.__UNSTABLE_OR_INTERNAL__
?.walletConnectListedDesktopWalletLink,
experimentalWallet: props.config.features?.experimentalWallet,
};
const { providers } = useWalletProviders(config.wallets, walletOptions);
const onConnectWalletHandler = useRef<OnWalletConnectionChange>();
Expand Down Expand Up @@ -209,10 +207,6 @@ function Main(props: PropsWithChildren<PropTypes>) {
autoConnect={!!isActiveTab}
configs={{
wallets: config.wallets,
isExperimentalEnabled: isFeatureEnabled(
'experimentalWallet',
config.features
),
}}>
{props.children}
</Provider>
Expand Down
11 changes: 2 additions & 9 deletions widget/embedded/src/hooks/useWalletList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,14 @@ interface API {
*/
export function useWalletList(params?: Params): API {
const { chain } = params || {};
const { config, connectedWallets, getAvailableProviders } = useAppStore();
const { connectedWallets, getAvailableProviders } = useAppStore();
const { state, getWalletInfo } = useWallets();
const blockchains = useAppStore().blockchains();
const { handleDisconnect } = useStatefulConnect();

/** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
const listAvailableWalletTypes = configWalletsToWalletName(
getAvailableProviders(),
{
trezorManifest: config?.trezorManifest,
walletConnectProjectId: config?.walletConnectProjectId,
walletConnectListedDesktopWalletLink:
config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
tonConnect: config.tonConnect,
}
getAvailableProviders()
);

let wallets = mapWalletTypesToWalletInfo(
Expand Down
4 changes: 0 additions & 4 deletions widget/embedded/src/store/slices/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function makeProvidersOptionsFromConfig(
tonConnect: config?.tonConnect,
walletConnectListedDesktopWalletLink:
config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
experimentalWallet: config.features?.experimentalWallet,
};

return options;
Expand All @@ -43,9 +42,6 @@ export const DEFAULT_CONFIG: WidgetConfig = {
manifestUrl:
'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/manifests/tonconnect-manifest.json',
},
features: {
experimentalWallet: 'enabled',
},
};

interface IframeConfigs {
Expand Down
3 changes: 0 additions & 3 deletions widget/embedded/src/store/slices/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const DEFAULT_CONFIG: WidgetConfig = {
manifestUrl:
'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/manifests/tonconnect-manifest.json',
},
features: {
experimentalWallet: 'enabled',
},
};

beforeEach(() => {
Expand Down
6 changes: 1 addition & 5 deletions widget/embedded/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ export type SignersConfig = {
*
* @property {'visible' | 'hidden'} [liquiditySource]
* - The visibility state for the liquiditySource feature. Optional property.
*
* @property {'disabled' | 'enabled'} [experimentalWallet]
* - Enable our experimental version of wallets. Default: disable on production, enabled on dev.
*/
export type Features = Partial<
Record<
Expand All @@ -148,8 +145,7 @@ export type Features = Partial<
| 'customTokens',
'visible' | 'hidden'
>
> &
Partial<Record<'experimentalWallet', 'disabled' | 'enabled'>>;
>;

/**
* `Routing`
Expand Down
23 changes: 6 additions & 17 deletions widget/embedded/src/utils/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface ProvidersOptions {
>['walletConnectListedDesktopWalletLink'];
trezorManifest: WidgetConfig['trezorManifest'];
tonConnect: WidgetConfig['tonConnect'];
experimentalWallet?: 'enabled' | 'disabled';
}

/**
Expand All @@ -28,7 +27,6 @@ type BothProvidersInterface = LegacyProviderInterface | Provider;
export function matchAndGenerateProviders({
allProviders,
configWallets,
options,
}: {
allProviders: VersionedProviders[];
configWallets: WidgetConfig['wallets'];
Expand Down Expand Up @@ -56,10 +54,8 @@ export function matchAndGenerateProviders({
* If the corresponding provider to a wallet was found in allProvider,
* it will be add to selected providers.
*/
const versionedProvider = pickProviderVersionWithFallbackToLegacy(
provider,
options
);
const versionedProvider =
pickProviderVersionWithFallbackToLegacy(provider);
if (versionedProvider instanceof Provider) {
return versionedProvider.id === requestedWallet;
}
Expand Down Expand Up @@ -100,28 +96,21 @@ export function matchAndGenerateProviders({
}

function pickProviderVersionWithFallbackToLegacy(
provider: VersionedProviders,
options?: ProvidersOptions
provider: VersionedProviders
): BothProvidersInterface {
const { experimentalWallet = 'enabled' } = options || {};
const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';

try {
return pickVersion(provider, version)[1];
return pickVersion(provider, '1.0.0')[1];
} catch {
// Fallback to legacy version, if target version doesn't exists.
return pickVersion(provider, '0.0.0')[1];
}
}

export function configWalletsToWalletName(
providers: VersionedProviders[],
options?: ProvidersOptions
providers: VersionedProviders[]
): string[] {
const names = providers
.map((provider) =>
pickProviderVersionWithFallbackToLegacy(provider, options)
)
.map((provider) => pickProviderVersionWithFallbackToLegacy(provider))
.map((provider) => {
if (provider instanceof Provider) {
return provider.id;
Expand Down
4 changes: 0 additions & 4 deletions widget/embedded/src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) {
return features?.[feature] === 'hidden';
}

export function isFeatureEnabled(feature: keyof Features, features?: Features) {
return features?.[feature] === 'enabled';
}

export function isRoutingEnabled(item: keyof Routing, routing?: Routing) {
return routing?.[item] === 'enabled';
}
Expand Down
1 change: 0 additions & 1 deletion widget/playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export function App() {
apiKey: RANGO_PUBLIC_API_KEY,
features: {
theme: 'hidden',
experimentalWallet: 'enabled',
},
__UNSTABLE_OR_INTERNAL__: {
autoUpdateSettings: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export function WalletSection() {
};
const allProviders = getAllProviders(envs);
const allBuiltProviders = allProviders.map((build) => build());
const [legacyProviders] = separateLegacyAndHubProviders(allBuiltProviders, {
isExperimentalEnabled: config.features?.experimentalWallet === 'enabled',
});
const [legacyProviders] = separateLegacyAndHubProviders(allBuiltProviders);
const filteredProviders = legacyProviders.filter(
(provider) =>
!excludedWallets.includes(provider.config.type as WalletTypes)
Expand Down

0 comments on commit 285f88b

Please sign in to comment.