Skip to content

Commit 8435f28

Browse files
committed
feat: migrate keplr to the hub
1 parent 42ba1ff commit 8435f28

File tree

18 files changed

+457
-96
lines changed

18 files changed

+457
-96
lines changed

wallets/provider-all/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { versions as enkrypt } from '@rango-dev/provider-enkrypt';
1616
import { versions as exodus } from '@rango-dev/provider-exodus';
1717
import * as frontier from '@rango-dev/provider-frontier';
1818
import * as halo from '@rango-dev/provider-halo';
19-
import * as keplr from '@rango-dev/provider-keplr';
19+
import { versions as keplr } from '@rango-dev/provider-keplr';
2020
import * as leapCosmos from '@rango-dev/provider-leap-cosmos';
2121
import { versions as ledger } from '@rango-dev/provider-ledger';
2222
import * as mathwallet from '@rango-dev/provider-math-wallet';
@@ -103,7 +103,7 @@ export const allProviders = (
103103
metamask,
104104
lazyProvider(legacyProviderImportsToVersionsInterface(walletconnect2)),
105105
lazyProvider(legacyProviderImportsToVersionsInterface(tonconnect)),
106-
lazyProvider(legacyProviderImportsToVersionsInterface(keplr)),
106+
keplr,
107107
phantom,
108108
lazyProvider(legacyProviderImportsToVersionsInterface(ready)),
109109
lazyProvider(legacyProviderImportsToVersionsInterface(tronLink)),

wallets/provider-keplr/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
"version": "0.54.2-next.3",
44
"license": "MIT",
55
"type": "module",
6-
"source": "./src/index.ts",
7-
"main": "./dist/index.js",
6+
"source": "./src/mod.ts",
7+
"main": "./dist/mod.js",
88
"exports": {
9-
".": "./dist/index.js"
9+
".": "./dist/mod.js",
10+
"./lib": "./dist/lib.js"
1011
},
11-
"typings": "dist/index.d.ts",
12+
"typings": "dist/mod.d.ts",
1213
"files": [
1314
"dist",
1415
"src"
1516
],
1617
"scripts": {
17-
"build": "node ../../scripts/build/command.mjs --path wallets/provider-keplr",
18+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-keplr --inputs src/mod.ts",
1819
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
1920
"clean": "rimraf dist",
2021
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
@@ -24,6 +25,7 @@
2425
"@rango-dev/signer-cosmos": "^0.38.0",
2526
"@rango-dev/wallets-core": "^0.53.1-next.2",
2627
"@rango-dev/wallets-shared": "^0.54.2-next.3",
28+
"@chain-registry/keplr": "^2.0.110",
2729
"rango-types": "^0.1.89"
2830
},
2931
"devDependencies": {
@@ -35,4 +37,4 @@
3537
"publishConfig": {
3638
"access": "public"
3739
}
38-
}
40+
}

wallets/provider-keplr/readme.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# @rango-dev/provider-keplr
1+
# Keplr
2+
Keplr integration for hub.
3+
[Homepage](https://www.keplr.app/) | [Docs](https://docs.keplr.app/)
4+
5+
More about implementation status can be found [here](../readme.md).
6+
7+
## Implementation notes/limitations
8+
9+
### Group
10+
11+
#### 🚧 EVM (Not Implemented)
12+
Keplr also provides support for **EVM networks**, but
13+
**EVM is not implemented** in the current integration.
14+
15+
### Feature
16+
17+
#### ⚠️ Auto Connect
18+
Keplr does **not provide any eager-connect (silent connection) mechanism**.
19+
A manual connection flow is required every time.
20+
21+
22+
---
23+
24+
More wallet information can be found in [readme.md](../readme.md).
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { Context, FunctionWithContext } from '@rango-dev/wallets-core';
2+
3+
import { chainRegistryChainToKeplr } from '@chain-registry/keplr';
4+
import {
5+
type CosmosActions,
6+
type ProviderAPI,
7+
utils,
8+
} from '@rango-dev/wallets-core/namespaces/cosmos';
9+
10+
import { getCosmosAccounts } from '../utils.js';
11+
12+
function connect(
13+
instance: () => ProviderAPI
14+
): FunctionWithContext<CosmosActions['connect'], Context> {
15+
return async (context, options) => {
16+
// Setting connect args to be used on other actions
17+
const [, setState] = context.state();
18+
setState('connectArgs', { options });
19+
const cosmosInstance = instance();
20+
if (!cosmosInstance) {
21+
throw new Error(
22+
'Do your wallet injected correctly and is cosmos compatible?'
23+
);
24+
}
25+
if (!options?.chainIds) {
26+
throw new Error(
27+
'Passing chainIds meta to the connect options is mandatory'
28+
);
29+
}
30+
31+
const providerAccounts = await getCosmosAccounts(
32+
cosmosInstance,
33+
options.chainIds,
34+
options.customChainIds
35+
);
36+
return utils.formatAccountsToCAIP(providerAccounts);
37+
};
38+
}
39+
function suggest(
40+
instance: () => ProviderAPI
41+
): FunctionWithContext<CosmosActions['suggest'], Context> {
42+
return async (_context, chain, assetList) => {
43+
const cosmosInstance = instance();
44+
if (!cosmosInstance) {
45+
throw new Error(
46+
'Is your wallet injected correctly and cosmos compatible?'
47+
);
48+
}
49+
const experimentalChain = chainRegistryChainToKeplr(chain, [assetList]);
50+
return await cosmosInstance.experimentalSuggestChain(experimentalChain);
51+
};
52+
}
53+
export const cosmosActions = { connect, suggest };
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type {
2+
CosmosActions,
3+
ProviderAPI,
4+
} from '@rango-dev/wallets-core/namespaces/cosmos';
5+
6+
import { ChangeAccountSubscriberBuilder } from '@rango-dev/wallets-core/namespaces/common';
7+
import { utils } from '@rango-dev/wallets-core/namespaces/cosmos';
8+
9+
// Hooks
10+
const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
11+
new ChangeAccountSubscriberBuilder<Event, ProviderAPI, CosmosActions>()
12+
.getInstance(getInstance)
13+
.onSwitchAccount((event, context) => {
14+
const [getState] = context.state();
15+
event.preventDefault();
16+
const connectArgs = getState('connectArgs');
17+
if (!connectArgs) {
18+
throw new Error('Connect args are empty');
19+
}
20+
context.action('disconnect');
21+
context.action('connect', connectArgs.options);
22+
})
23+
.format(async (_, __) => utils.formatAccountsToCAIP([]))
24+
.addEventListener((_, callback) => {
25+
window.addEventListener('keplr_keystorechange', callback);
26+
})
27+
.removeEventListener((_, callback) => {
28+
window.removeEventListener('keplr_keystorechange', callback);
29+
});
30+
31+
export const cosmosBuilders = { changeAccountSubscriber };
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { type ProviderMetadata } from '@rango-dev/wallets-core';
2+
import { type BlockchainMeta, cosmosBlockchains } from 'rango-types';
3+
4+
import getSigners from './signer.js';
5+
import { getInstanceOrThrow } from './utils.js';
6+
7+
export const WALLET_ID = 'keplr';
8+
9+
export const metadata: ProviderMetadata = {
10+
name: 'Keplr',
11+
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/keplr/icon.svg',
12+
extensions: {
13+
chrome:
14+
'https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap',
15+
brave:
16+
'https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap',
17+
firefox: 'https://addons.mozilla.org/en-US/firefox/addon/keplr',
18+
homepage: 'https://www.keplr.app',
19+
},
20+
properties: [
21+
{
22+
name: 'namespaces',
23+
value: {
24+
selection: 'multiple',
25+
data: [
26+
{
27+
label: 'Cosmos',
28+
value: 'Cosmos',
29+
id: 'Cosmos',
30+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
31+
cosmosBlockchains(allBlockchains),
32+
},
33+
],
34+
},
35+
},
36+
{
37+
name: 'signers',
38+
value: { getSigners: async () => getSigners(getInstanceOrThrow()) },
39+
},
40+
],
41+
};

wallets/provider-keplr/src/helpers.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

wallets/provider-keplr/src/index.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

wallets/provider-keplr/src/libs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { cosmosActions as keplrCosmosActions } from './actions/cosmos.js';
2+
export { getCosmosAccounts as keplrGetCosmosAccounts } from './utils.js';

wallets/provider-keplr/src/mod.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineVersions } from '@rango-dev/wallets-core/utils';
2+
3+
import { buildProvider } from './provider.js';
4+
5+
const versions = () =>
6+
defineVersions().version('1.0.0', buildProvider()).build();
7+
8+
export { versions };

0 commit comments

Comments
 (0)