Skip to content

Commit 9357d5c

Browse files
committed
refactor: improved some types
1 parent d5d50ab commit 9357d5c

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

wallets/core/src/namespaces/evm/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface EvmActions
1010
CommonActions {
1111
connect: (
1212
chain?: Chain | ChainId,
13-
derivationPath?: string
13+
options?: ConnectOptions
1414
) => Promise<AccountsWithActiveChain>;
1515
canEagerConnect: () => Promise<boolean>;
1616
}
@@ -22,4 +22,5 @@ export type Chain = AddEthereumChainParameter;
2222

2323
export type ConnectOptions = {
2424
switchOrAddNetwork?: (instance: ProviderAPI, chain: ChainId | Chain) => void;
25+
derivationPath?: string;
2526
};

wallets/core/src/namespaces/solana/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
export interface SolanaActions
88
extends AutoImplementedActionsByRecommended,
99
CommonActions {
10-
connect: (network?: unknown, derivationPath?: string) => Promise<Accounts>;
10+
connect: (network?: unknown, options?: ConnectOptions) => Promise<Accounts>;
1111
canEagerConnect: () => Promise<boolean>;
1212
}
1313

@@ -20,3 +20,7 @@ export interface SolanaActions
2020
*/
2121
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2222
export type ProviderAPI = Record<string, any>;
23+
24+
export type ConnectOptions = {
25+
derivationPath?: string;
26+
};

wallets/provider-ledger/src/namespaces/evm.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
CAIP_NAMESPACE,
1111
} from '@rango-dev/wallets-core/namespaces/evm';
1212
import { CAIP } from '@rango-dev/wallets-core/utils';
13-
import { ETHEREUM_CHAIN_ID } from '@rango-dev/wallets-shared';
1413

1514
import { WALLET_ID } from '../constants.js';
1615
import { setDerivationPath } from '../state.js';
@@ -21,12 +20,12 @@ import {
2120

2221
const connect = builders
2322
.connect()
24-
.action(async function (_context, chain, derivationPath) {
25-
if (!derivationPath) {
23+
.action(async function (_context, _chain, options) {
24+
if (!options?.derivationPath) {
2625
throw new Error('Derivation Path can not be empty.');
2726
}
2827

29-
setDerivationPath(derivationPath);
28+
setDerivationPath(options.derivationPath);
3029

3130
const result = await getEthereumAccounts();
3231

@@ -36,14 +35,14 @@ const connect = builders
3635
address: account,
3736
chainId: {
3837
namespace: CAIP_NAMESPACE,
39-
reference: ETHEREUM_CHAIN_ID,
38+
reference: result.chainId,
4039
},
4140
}) as CaipAccount
4241
);
4342

4443
return {
4544
accounts: formatAccounts,
46-
network: ETHEREUM_CHAIN_ID,
45+
network: result.chainId,
4746
};
4847
})
4948
.or(standardizeAndThrowLedgerError)

wallets/provider-ledger/src/namespaces/solana.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { builders as commonBuilders } from '@rango-dev/wallets-core/namespaces/c
66
import {
77
builders,
88
CAIP_NAMESPACE,
9-
CAIP_SOLANA_CHAIN_ID,
109
} from '@rango-dev/wallets-core/namespaces/solana';
1110
import { CAIP } from '@rango-dev/wallets-core/utils';
1211

@@ -16,12 +15,12 @@ import { getSolanaAccounts, standardizeAndThrowLedgerError } from '../utils.js';
1615

1716
const connect = builders
1817
.connect()
19-
.action(async function (_context, _chain, derivationPath) {
20-
if (!derivationPath) {
18+
.action(async function (_context, _chain, options) {
19+
if (!options?.derivationPath) {
2120
throw new Error('Derivation Path can not be empty.');
2221
}
2322

24-
setDerivationPath(derivationPath);
23+
setDerivationPath(options.derivationPath);
2524

2625
const result = await getSolanaAccounts();
2726

@@ -31,7 +30,7 @@ const connect = builders
3130
address: account,
3231
chainId: {
3332
namespace: CAIP_NAMESPACE,
34-
reference: CAIP_SOLANA_CHAIN_ID,
33+
reference: result.chainId,
3534
},
3635
}) as CaipAccount
3736
);

wallets/provider-ledger/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type Transport from '@ledgerhq/hw-transport';
22

33
import { getAltStatusMessage } from '@ledgerhq/errors';
44
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
5+
import { CAIP_SOLANA_CHAIN_ID } from '@rango-dev/wallets-core/namespaces/solana';
56
import {
67
ETHEREUM_CHAIN_ID,
78
type ProviderConnectResult,
@@ -100,7 +101,7 @@ export async function getSolanaAccounts(): Promise<ProviderConnectResult> {
100101

101102
return {
102103
accounts: accounts,
103-
chainId: LegacyNetworks.SOLANA,
104+
chainId: CAIP_SOLANA_CHAIN_ID,
104105
derivationPath,
105106
};
106107
} catch (error: unknown) {

wallets/react/src/hub/useHubAdapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
188188
*/
189189
const connectNamespaceProcess = async () =>
190190
namespace
191-
.connect(network, namespaceInput.derivationPath)
191+
.connect(network, {
192+
derivationPath: namespaceInput.derivationPath,
193+
})
192194
.then<ConnectResult>(transformHubResultToLegacyResult)
193195
.then((connectResult) => {
194196
return {

0 commit comments

Comments
 (0)