Skip to content

Commit

Permalink
chore: change Namespace enum to stirng
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Dec 16, 2024
1 parent 5b7b400 commit 1ebabfb
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 78 deletions.
8 changes: 8 additions & 0 deletions wallets/core/namespaces/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@rango-dev/wallets-core/namespaces/common",
"type": "module",
"main": "../../dist/namespaces/common/mod.js",
"module": "../../dist/namespaces/common/mod.js",
"types": "../../dist/namespaces/common/mod.d.ts",
"sideEffects": false
}
8 changes: 8 additions & 0 deletions wallets/core/namespaces/evm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@rango-dev/wallets-core/namespaces/evm",
"type": "module",
"main": "../../dist/namespaces/evm/mod.js",
"module": "../../dist/namespaces/evm/mod.js",
"types": "../../dist/namespaces/evm/mod.d.ts",
"sideEffects": false
}
8 changes: 8 additions & 0 deletions wallets/core/namespaces/solana/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@rango-dev/wallets-core/namespaces/solana",
"type": "module",
"main": "../../dist/namespaces/solana/mod.js",
"module": "../../dist/namespaces/solana/mod.js",
"types": "../../dist/namespaces/solana/mod.d.ts",
"sideEffects": false
}
6 changes: 1 addition & 5 deletions wallets/core/src/legacy/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ export type {
NamespaceInputWithDiscoverMode as LegacyNamespaceInputWithDiscoverMode,
} from './types.js';

export {
Events as LegacyEvents,
Namespace as LegacyNamespace,
Networks as LegacyNetworks,
} from './types.js';
export { Events as LegacyEvents, Networks as LegacyNetworks } from './types.js';

export { Persistor } from './persistor.js';
export {
Expand Down
19 changes: 2 additions & 17 deletions wallets/core/src/legacy/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { State as WalletState } from './wallet.js';
import type { Namespace } from '../namespaces/common/mod.js';
import type { BlockchainMeta, SignerFactory } from 'rango-types';

export enum Networks {
Expand Down Expand Up @@ -64,15 +65,6 @@ export enum Networks {
Unknown = 'Unkown',
}

export enum Namespace {
Solana = 'Solana',
Evm = 'EVM',
Cosmos = 'Cosmos',
Utxo = 'UTXO',
Starknet = 'Starknet',
Tron = 'Tron',
}

export type NamespaceData = {
namespace: Namespace;
derivationPath?: string;
Expand Down Expand Up @@ -248,13 +240,6 @@ export type ProviderInterface = { config: WalletConfig } & WalletActions;
// it comes from wallets.ts and `connect`
type NetworkTypeFromLegacyConnect = Network | undefined;

export type NetworkTypeForNamespace<T extends NamespacesWithDiscoverMode> =
T extends 'DISCOVER_MODE'
? string
: T extends Namespace
? NetworkTypeFromLegacyConnect
: never;

export type NamespacesWithDiscoverMode = Namespace | 'DISCOVER_MODE';

export type NamespaceInputWithDiscoverMode = {
Expand All @@ -273,7 +258,7 @@ export type NamespaceInputForConnect<T extends Namespace = Namespace> =
/**
* In some cases, we need to connect a specific network on a namespace. e.g. Polygon on EVM.
*/
network: NetworkTypeForNamespace<T>;
network: NetworkTypeFromLegacyConnect;
derivationPath?: string;
}
| NamespaceInputWithDiscoverMode;
6 changes: 2 additions & 4 deletions wallets/core/src/legacy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import type {
NamespaceInputWithDiscoverMode,
} from './types.js';

import { Namespace } from './types.js';

export async function eagerConnectHandler<R = unknown>(params: {
canEagerConnect: () => Promise<boolean>;
connectHandler: () => Promise<R>;
Expand All @@ -26,6 +24,6 @@ export function isNamespaceDiscoverMode(

export function isEvmNamespace(
namespace: NamespaceInputForConnect
): namespace is NamespaceInputForConnect<Namespace.Evm> {
return namespace.namespace === Namespace.Evm;
): namespace is NamespaceInputForConnect<'EVM'> {
return namespace.namespace === 'EVM';
}
2 changes: 2 additions & 0 deletions wallets/core/src/namespaces/common/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export type {
Accounts,
AccountsWithActiveChain,
} from '../../types/accounts.js';

export type { Namespace } from './types.js';
16 changes: 16 additions & 0 deletions wallets/core/src/namespaces/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* These are supported namespaces in Rango that we want to officially support.
* This should be private and don't make it public since core can support more namespaces and should be extendable.
*/
type RangoNamespace =
| 'EVM'
| 'Solana'
| 'Cosmos'
| 'UTXO'
| 'Starknet'
| 'Tron'
| 'Ton';

// eslint-disable-next-line @typescript-eslint/ban-types
export type Namespace = RangoNamespace | (string & {});

export interface CommonActions {
init: () => void;
}
Expand Down
8 changes: 4 additions & 4 deletions wallets/provider-ledger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
WalletInfo,
} from '@rango-dev/wallets-shared';

import { Namespace, Networks, WalletTypes } from '@rango-dev/wallets-shared';
import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
import { type BlockchainMeta, type SignerFactory } from 'rango-types';

import {
Expand All @@ -26,10 +26,10 @@ export const connect: Connect = async ({ namespaces }) => {
const results: ProviderConnectResult[] = [];

const solanaNamespace = namespaces?.find(
(namespaceItem) => namespaceItem.namespace === Namespace.Solana
(namespaceItem) => namespaceItem.namespace === 'Solana'
);
const evmNamespace = namespaces?.find(
(namespaceItem) => namespaceItem.namespace === Namespace.Evm
(namespaceItem) => namespaceItem.namespace === 'EVM'
);

if (solanaNamespace) {
Expand Down Expand Up @@ -93,7 +93,7 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
},
color: 'black',
supportedChains,
namespaces: [Namespace.Evm, Namespace.Solana],
namespaces: ['EVM', 'Solana'],
singleNamespace: true,
showOnMobile: false,
needsDerivationPath: true,
Expand Down
6 changes: 3 additions & 3 deletions wallets/provider-trezor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
WalletInfo,
} from '@rango-dev/wallets-shared';

import { Namespace, Networks, WalletTypes } from '@rango-dev/wallets-shared';
import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
import { type BlockchainMeta, type SignerFactory } from 'rango-types';

import {
Expand Down Expand Up @@ -40,7 +40,7 @@ export const connect: Connect = async ({ namespaces }) => {
const TrezorConnect = await getTrezorModule();

const evmNamespace = namespaces?.find(
(namespaceItem) => namespaceItem.namespace === Namespace.Evm
(namespaceItem) => namespaceItem.namespace === 'EVM'
);

if (evmNamespace) {
Expand Down Expand Up @@ -95,7 +95,7 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
},
color: 'black',
supportedChains,
namespaces: [Namespace.Evm],
namespaces: ['EVM'],
singleNamespace: true,
showOnMobile: false,
needsDerivationPath: true,
Expand Down
2 changes: 1 addition & 1 deletion wallets/react/src/hub/autoConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { Hub } from '@rango-dev/wallets-core';
import type {
LegacyNamespaceInputForConnect,
LegacyProviderInterface,
LegacyNamespace as Namespace,
} from '@rango-dev/wallets-core/legacy';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

import {
legacyEagerConnectHandler,
Expand Down
6 changes: 2 additions & 4 deletions wallets/react/src/hub/useHubAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { AllProxiedNamespaces, ExtensionLink } from './types.js';
import type { Providers } from '../index.js';
import type { Provider } from '@rango-dev/wallets-core';
import type {
LegacyNamespaceInputForConnect,
LegacyNamespace as Namespace,
} from '@rango-dev/wallets-core/legacy';
import type { LegacyNamespaceInputForConnect } from '@rango-dev/wallets-core/legacy';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
import type { VersionedProviders } from '@rango-dev/wallets-core/utils';

import { legacyIsNamespaceDiscoverMode } from '@rango-dev/wallets-core/legacy';
Expand Down
17 changes: 8 additions & 9 deletions wallets/react/src/hub/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import type {
LegacyProviderInterface,
LegacyEventHandler as WalletEventHandler,
} from '@rango-dev/wallets-core/legacy';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

import {
guessProviderStateSelector,
namespaceStateSelector,
} from '@rango-dev/wallets-core';
import {
LegacyEvents as Events,
LegacyNamespace as Namespace,
} from '@rango-dev/wallets-core/legacy';
import { LegacyEvents as Events } from '@rango-dev/wallets-core/legacy';
import {
generateStoreId,
type VersionedProviders,
Expand Down Expand Up @@ -269,7 +267,7 @@ export function discoverNamespace(network: string): Namespace {
case Networks.TERRA:
case Networks.THORCHAIN:
case Networks.UMEE:
return Namespace.Cosmos;
return 'Cosmos';
case Networks.AVAX_CCHAIN:
case Networks.ARBITRUM:
case Networks.BOBA:
Expand All @@ -284,17 +282,18 @@ export function discoverNamespace(network: string): Namespace {
case Networks.OPTIMISM:
case Networks.POLYGON:
case Networks.STARKNET:
return Namespace.Evm;
return 'Evm';
case Networks.SOLANA:
return Namespace.Solana;
return 'Solana';
case Networks.BTC:
case Networks.BCH:
case Networks.DOGE:
case Networks.LTC:
case Networks.TRON:
return Namespace.Utxo;
case Networks.POLKADOT:
return 'UTXO';
case Networks.TON:
return 'Ton';
case Networks.POLKADOT:
case Networks.AXELAR:
case Networks.MARS:
case Networks.MAYA:
Expand Down
23 changes: 12 additions & 11 deletions wallets/shared/src/rango.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import type {
LegacyWalletInfo as WalletInfo,
LegacyWalletType as WalletType,
} from '@rango-dev/wallets-core/legacy';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
import type { BlockchainMeta, EvmBlockchainMeta } from 'rango-types';

import {
LegacyNamespace as Namespace,
LegacyNetworks as Networks,
} from '@rango-dev/wallets-core/legacy';
import { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';

export type {
LegacyNetwork as Network,
Expand All @@ -27,7 +25,6 @@ export type {

export {
LegacyNetworks as Networks,
LegacyNamespace as Namespace,
legacyGetBlockChainNameFromId as getBlockChainNameFromId,
} from '@rango-dev/wallets-core/legacy';

Expand Down Expand Up @@ -82,7 +79,7 @@ export const namespaces: Record<
Namespace,
{ mainBlockchain: string; title: string; derivationPaths?: DerivationPath[] }
> = {
[Namespace.Evm]: {
EVM: {
mainBlockchain: 'ETH',
title: 'Ethereum',
derivationPaths: [
Expand All @@ -103,7 +100,7 @@ export const namespaces: Record<
},
],
},
[Namespace.Solana]: {
Solana: {
mainBlockchain: 'SOLANA',
title: 'Solana',
derivationPaths: [
Expand All @@ -119,22 +116,26 @@ export const namespaces: Record<
},
],
},
[Namespace.Cosmos]: {
Cosmos: {
mainBlockchain: 'COSMOS',
title: 'Cosmos',
},
[Namespace.Utxo]: {
UTXO: {
mainBlockchain: 'BTC',
title: 'Utxo',
},
[Namespace.Starknet]: {
Starknet: {
title: 'Starknet',
mainBlockchain: 'STARKNET',
},
[Namespace.Tron]: {
Tron: {
title: 'Tron',
mainBlockchain: 'TRON',
},
Ton: {
title: 'Ton',
mainBlockchain: 'TON',
},
};

export type DerivationPath = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Result } from '../../hooks/useStatefulConnect';
import type { WalletInfoWithExtra } from '../../types';
import type { Namespace } from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

import { Divider } from '@rango-dev/ui';
import React, { useEffect, useRef, useState } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
import type { DerivationPath } from '@rango-dev/wallets-shared';

import { namespaces } from '@rango-dev/wallets-shared';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PropTypes } from './Namespaces.types';
import type { Namespace } from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

import { i18n } from '@lingui/core';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
import type { Namespace } from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

export interface PropTypes {
onConfirm: (namespaces: Namespace[]) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { HandleConnectOptions, Result } from './useStatefulConnect.types';
import type { WalletInfoWithExtra } from '../../types';
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
import type {
Namespace,
NamespaceData,
WalletType,
} from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
import type { NamespaceData, WalletType } from '@rango-dev/wallets-shared';

import { WalletState } from '@rango-dev/ui';
import { useWallets } from '@rango-dev/wallets-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Namespace } from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

export interface HandleConnectOptions {
// To have a switch between connect and disconnect when user is clicking on a button, this option can be helpful.
Expand Down
3 changes: 2 additions & 1 deletion widget/embedded/src/types/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { WalletInfo } from '@rango-dev/ui';
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
import type { WalletType } from '@rango-dev/wallets-shared';

export interface Wallet {
chain: string;
Expand Down
Loading

0 comments on commit 1ebabfb

Please sign in to comment.