Skip to content

Commit 7bf7631

Browse files
committed
feat: migrate ready to the hub
1 parent 62ae227 commit 7bf7631

File tree

15 files changed

+276
-134
lines changed

15 files changed

+276
-134
lines changed

wallets/provider-all/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { versions as metamask } from '@rango-dev/provider-metamask';
2424
import { versions as okx } from '@rango-dev/provider-okx';
2525
import { versions as phantom } from '@rango-dev/provider-phantom';
2626
import { versions as rabby } from '@rango-dev/provider-rabby';
27-
import * as ready from '@rango-dev/provider-ready';
27+
import { versions as ready } from '@rango-dev/provider-ready';
2828
import * as safe from '@rango-dev/provider-safe';
2929
import { versions as safepal } from '@rango-dev/provider-safepal';
3030
import { versions as slush } from '@rango-dev/provider-slush';
@@ -104,7 +104,7 @@ export const allProviders = (
104104
lazyProvider(legacyProviderImportsToVersionsInterface(tonconnect)),
105105
lazyProvider(legacyProviderImportsToVersionsInterface(keplr)),
106106
phantom,
107-
lazyProvider(legacyProviderImportsToVersionsInterface(ready)),
107+
ready,
108108
lazyProvider(legacyProviderImportsToVersionsInterface(tronLink)),
109109
trustwallet,
110110
lazyProvider(legacyProviderImportsToVersionsInterface(bitget)),

wallets/provider-ready/package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,26 @@
33
"version": "0.52.1-next.1",
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"
1010
},
11-
"typings": "dist/index.d.ts",
12-
"files": [
13-
"dist",
14-
"src"
15-
],
11+
"typings": "dist/mod.d.ts",
1612
"scripts": {
17-
"build": "node ../../scripts/build/command.mjs --path wallets/provider-ready",
13+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-ready --inputs src/mod.ts",
1814
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
1915
"clean": "rimraf dist",
2016
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
2117
"lint": "eslint \"**/*.{ts,tsx}\""
2218
},
2319
"dependencies": {
2420
"@rango-dev/signer-starknet": "^0.40.0",
21+
"@rango-dev/wallets-core": "^0.52.0",
2522
"@rango-dev/wallets-shared": "^0.52.1-next.1",
2623
"rango-types": "^0.1.89"
2724
},
2825
"publishConfig": {
2926
"access": "public"
3027
}
31-
}
28+
}

wallets/provider-ready/readme.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# @rango-dev/provider-ready
1+
# Ready (formerly Argent X)
2+
Ready Wallet integration for hub.
3+
[Homepage](https://www.ready.tech/) | [Docs](https://docs.ready.tech/)
4+
5+
More about implementation status can be found [here](../readme.md).
6+
7+
## Implementation notes/limitations
8+
9+
### Feature
10+
All features are currently supported, and **no limitations** have been identified in this integration.
11+
12+
---
13+
14+
More wallet information can be found in [readme.md](../readme.md).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Context, FunctionWithContext } from '@rango-dev/wallets-core';
2+
3+
import {
4+
CAIP_STARKNET_CHAIN_ID,
5+
type ProviderAPI,
6+
type StarknetActions,
7+
utils,
8+
} from '@rango-dev/wallets-core/namespaces/starknet';
9+
10+
export function connect(
11+
instance: () => ProviderAPI
12+
): FunctionWithContext<StarknetActions['connect'], Context> {
13+
return async () => {
14+
const starknetInstance = instance();
15+
16+
const connectResult = await starknetInstance?.enable();
17+
if (
18+
!connectResult ||
19+
!starknetInstance.isConnected ||
20+
!connectResult?.length
21+
) {
22+
throw new Error('Error during connection');
23+
}
24+
if (starknetInstance?.chainId !== CAIP_STARKNET_CHAIN_ID) {
25+
throw new Error(
26+
`Please switch to Mainnet, current network is ${starknetInstance?.chainId}`
27+
);
28+
}
29+
30+
return utils.formatAccountsToCAIP(connectResult);
31+
};
32+
}
33+
export const starknetActions = { connect };
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/starknet';
2+
3+
import { ChangeAccountSubscriberBuilder } from '@rango-dev/wallets-core/namespaces/common';
4+
import { utils } from '@rango-dev/wallets-core/namespaces/starknet';
5+
// Hooks
6+
export const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
7+
new ChangeAccountSubscriberBuilder<string[], ProviderAPI>()
8+
.getInstance(getInstance)
9+
10+
.onSwitchAccount((event) => {
11+
if (!event.payload.length) {
12+
event.preventDefault();
13+
}
14+
})
15+
.format(async (_, accounts) => utils.formatAccountsToCAIP(accounts))
16+
.addEventListener((instance, callback) => {
17+
instance.on('accountsChanged', callback);
18+
})
19+
.removeEventListener((instance, callback) => {
20+
instance.off('accountsChanged', callback);
21+
});
22+
23+
export const starknetBuilders = { changeAccountSubscriber };
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { type ProviderMetadata } from '@rango-dev/wallets-core';
2+
import { type BlockchainMeta, starknetBlockchain } from 'rango-types';
3+
4+
import getSigners from './signer.js';
5+
import { getInstanceOrThrow } from './utils.js';
6+
7+
export const WALLET_ID = 'ready';
8+
export const metadata: ProviderMetadata = {
9+
name: 'Ready',
10+
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/argentx/icon.svg',
11+
extensions: {
12+
chrome:
13+
'https://chromewebstore.google.com/detail/ready-wallet-formerly-arg/dlcobpjiigpikoobohmabehhmhfoodbb',
14+
brave:
15+
'https://chromewebstore.google.com/detail/ready-wallet-formerly-arg/dlcobpjiigpikoobohmabehhmhfoodbb',
16+
firefox: 'https://addons.mozilla.org/en-GB/firefox/addon/argent-x',
17+
homepage: 'https://www.ready.co/',
18+
},
19+
properties: [
20+
{
21+
name: 'namespaces',
22+
value: {
23+
selection: 'multiple',
24+
data: [
25+
{
26+
label: 'Ready',
27+
value: 'Starknet',
28+
id: 'STARKNET',
29+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
30+
starknetBlockchain(allBlockchains),
31+
},
32+
],
33+
},
34+
},
35+
{
36+
name: 'signers',
37+
value: { getSigners: async () => getSigners(getInstanceOrThrow()) },
38+
},
39+
],
40+
};

wallets/provider-ready/src/helpers.ts

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

wallets/provider-ready/src/index.ts

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

wallets/provider-ready/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 };
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { StarknetActions } from '@rango-dev/wallets-core/namespaces/starknet';
2+
3+
import { NamespaceBuilder } from '@rango-dev/wallets-core';
4+
import {
5+
builders as commonBuilders,
6+
standardizeAndThrowError,
7+
} from '@rango-dev/wallets-core/namespaces/common';
8+
import { actions, builders } from '@rango-dev/wallets-core/namespaces/starknet';
9+
10+
import { starknetActions } from '../actions/starknet.js';
11+
import { starknetBuilders } from '../builders/starknet.js';
12+
import { WALLET_ID } from '../constants.js';
13+
import { starknetReady } from '../utils.js';
14+
15+
const [changeAccountSubscriber, changeAccountCleanup] = starknetBuilders
16+
.changeAccountSubscriber(starknetReady)
17+
.build();
18+
const connect = builders
19+
.connect()
20+
.action(starknetActions.connect(starknetReady))
21+
.before(changeAccountSubscriber)
22+
.or(changeAccountCleanup)
23+
.or(standardizeAndThrowError)
24+
.build();
25+
26+
const disconnect = commonBuilders
27+
.disconnect<StarknetActions>()
28+
.after(changeAccountCleanup)
29+
.build();
30+
31+
const canEagerConnect = builders
32+
.canEagerConnect()
33+
.action(actions.canEagerConnect(starknetReady))
34+
.build();
35+
36+
const starknet = new NamespaceBuilder<StarknetActions>('Starknet', WALLET_ID)
37+
.action(connect)
38+
.action(disconnect)
39+
.action(canEagerConnect)
40+
.build();
41+
42+
export { starknet };

0 commit comments

Comments
 (0)