Skip to content

Commit fa454c8

Browse files
committed
update
1 parent 97fa94c commit fa454c8

File tree

16 files changed

+189
-95
lines changed

16 files changed

+189
-95
lines changed

signers/signer-cosmos-snap/CHANGELOG.md

-58
This file was deleted.

signers/signer-cosmos-snap/readme.md

-1
This file was deleted.

signers/signer-cosmos-snap/src/index.ts

-1
This file was deleted.
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# [0.14.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.14.0) (2023-08-03)
2+
3+
4+
5+
# [0.13.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.13.0) (2023-08-01)
6+
7+
8+
9+
# [0.9.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.9.0) (2023-07-31)
10+
11+
12+
13+
# [0.7.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.7.0) (2023-07-11)
14+
15+
16+
17+
# [0.6.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.6.0) (2023-07-11)
18+
19+
20+
### Reverts
21+
22+
* Revert "support for rango-types cjs format" ([ed4e050](https://github.com/rango-exchange/rango-client/commit/ed4e050bfc0dcde7aeffa6b0d73b02080a5721eb))
23+
* Revert "support for rango-types cjs format" ([4f5f55f](https://github.com/rango-exchange/rango-client/commit/4f5f55f96e8daa329588b932b19c291c30f339c4))
24+
25+
26+
27+
# [0.5.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.5.0) (2023-05-31)
28+
29+
30+
31+
# [0.4.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.4.0) (2023-05-31)
32+
33+
34+
35+
# [0.3.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.3.0) (2023-05-30)
36+
37+
38+
39+
# [0.2.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.2.0) (2023-05-30)
40+
41+
42+
43+
## [0.1.14](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.1.14) (2023-05-15)
44+
45+
46+
### Bug Fixes
47+
48+
* update rango-types and fix notification bugs ([993f185](https://github.com/rango-exchange/rango-client/commit/993f185e0b8c5e5e15a2c65ba2d85d1f9c8daa90))
49+
50+
51+

signers/signer-cosmos-snap/package.json wallets/provider-cosmos-snap/package.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@rango-dev/signer-cosmos-snap",
3-
"version": "0.17.0",
2+
"name": "@rango-dev/provider-cosmos-snap",
3+
"version": "0.17.1-next.1",
44
"license": "MIT",
55
"type": "module",
66
"module": "./dist/index.js",
@@ -14,15 +14,13 @@
1414
"src"
1515
],
1616
"scripts": {
17-
"build": "node ../../scripts/build/command.mjs --path signers/signer-cosmos-snap",
17+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-cosmos-snap",
1818
"clean": "rimraf dist",
1919
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
20-
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore",
21-
"test": "vitest",
22-
"test:watch": "vitest --watch",
23-
"test:coverage": "vitest run --coverage"
20+
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
2421
},
2522
"dependencies": {
23+
"@rango-dev/wallets-shared": "^0.17.1-next.1",
2624
"rango-types": "^0.1.46",
2725
"@cosmjs/amino": "^0.31.3",
2826
"@cosmjs/proto-signing": "^0.30.1",
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @rango-dev/provider-cosmos-snap

wallets/provider-metamask/src/snap.ts wallets/provider-cosmos-snap/src/helpers.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
export const DEFAULT_SNAP_ID = 'npm:@cosmsnap/snap';
1+
import { getCoinbaseInstance } from '@rango-dev/wallets-shared';
2+
3+
import { DEFAULT_SNAP_ID } from './signers/helpers';
4+
5+
export function metamask() {
6+
const isCoinbaseWalletAvailable = !!getCoinbaseInstance();
7+
const { ethereum } = window;
8+
9+
// Some wallets overriding the metamask. So we need to get it properly.
10+
if (isCoinbaseWalletAvailable) {
11+
// Getting intance from overrided structure from coinbase.
12+
return getCoinbaseInstance('metamask');
13+
}
14+
if (!!ethereum && ethereum.isMetaMask) {
15+
return ethereum;
16+
}
17+
18+
return null;
19+
}
220

321
export const isCosmosSnapInstalled = async (instance: any) => {
422
const result = await instance.request({ method: 'wallet_getSnaps' });
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import type {
2+
CanEagerConnect,
3+
CanSwitchNetwork,
4+
Connect,
5+
ProviderConnectResult,
6+
Subscribe,
7+
WalletInfo,
8+
} from '@rango-dev/wallets-shared';
9+
import type { BlockchainMeta, SignerFactory } from 'rango-types';
10+
11+
import {
12+
canEagerlyConnectToEvm,
13+
subscribeToEvm,
14+
WalletTypes,
15+
} from '@rango-dev/wallets-shared';
16+
import { cosmosBlockchains } from 'rango-types';
17+
18+
import {
19+
getAddresses,
20+
installCosmosSnap,
21+
isCosmosSnapInstalled,
22+
metamask as metamask_instance,
23+
} from './helpers';
24+
import signer from './signer';
25+
26+
const WALLET = WalletTypes.COSMOS_SNAP;
27+
28+
export const config = {
29+
type: WALLET,
30+
};
31+
32+
export const getInstance = metamask_instance;
33+
export const connect: Connect = async ({ instance }) => {
34+
/*
35+
* cosmos snap (It's optional)
36+
* If the user approves to install Snap, we take the Cosmos addresses and add them to the accounts.
37+
*/
38+
await installCosmosSnap(instance);
39+
const installed = await isCosmosSnapInstalled(instance);
40+
let accounts: ProviderConnectResult[] = [];
41+
if (installed) {
42+
const addresses = await getAddresses(instance);
43+
accounts = addresses.map((item) => ({
44+
accounts: [item.address],
45+
chainId: item.chain_id,
46+
}));
47+
}
48+
if (!accounts.length) {
49+
throw new Error('You have rejected to install cosmos-snap');
50+
}
51+
return accounts;
52+
};
53+
54+
export const subscribe: Subscribe = subscribeToEvm;
55+
56+
export const canSwitchNetworkTo: CanSwitchNetwork = () => false;
57+
58+
export const getSigners: (provider: any) => SignerFactory = signer;
59+
60+
export const canEagerConnect: CanEagerConnect = canEagerlyConnectToEvm;
61+
62+
export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
63+
allBlockChains
64+
) => {
65+
const cosmos = cosmosBlockchains(allBlockChains);
66+
return {
67+
name: 'Cosmos Snap',
68+
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/metamask/icon.svg',
69+
installLink: {
70+
CHROME:
71+
'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en',
72+
BRAVE:
73+
'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en',
74+
75+
FIREFOX: 'https://addons.mozilla.org/en-US/firefox/addon/ether-metamask',
76+
EDGE: 'https://microsoftedge.microsoft.com/addons/detail/metamask/ejbalbakoplchlghecdalmeeeajnimhm?hl=en-US',
77+
DEFAULT: 'https://metamask.io/download/',
78+
},
79+
color: '#dac7ae',
80+
supportedChains: cosmos,
81+
};
82+
};
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { SignerFactory } from 'rango-types';
2+
3+
import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
4+
5+
import StarknetSigner from './signers/cosmos';
6+
7+
export default function getSigners(provider: any): SignerFactory {
8+
const signers = new DefaultSignerFactory();
9+
signers.registerSigner(TxType.STARKNET, new StarknetSigner(provider));
10+
return signers;
11+
}

signers/signer-cosmos-snap/src/signer.ts wallets/provider-cosmos-snap/src/signers/cosmos.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type { GenericSigner } from 'rango-types';
44
import type { CosmosTransaction } from 'rango-types/lib/api/main';
55

6-
import { DEFAULT_SNAP_ID, executeTransaction } from './helper';
6+
import { DEFAULT_SNAP_ID, executeTransaction } from './helpers';
77

88
export class DefaultCosmosSnapSigner
99
implements GenericSigner<CosmosTransaction>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface AccContract {
2+
addressSalt: string;
3+
publicKey: string; // in hex
4+
address: string; // in hex
5+
addressIndex: number;
6+
derivationPath: string;
7+
deployTxnHash: string; // in hex
8+
chainId: string; // in hex
9+
}

signers/signer-cosmos-snap/tsconfig.json wallets/provider-cosmos-snap/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
33
"extends": "../../tsconfig.lib.json",
4-
"include": ["src", "types"],
4+
"include": ["src", "types", "../../global-wallets-env.d.ts"],
55
"compilerOptions": {
66
"outDir": "dist",
77
"rootDir": "./src",

wallets/provider-metamask/src/index.ts

+8-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {
22
CanEagerConnect,
33
CanSwitchNetwork,
44
Connect,
5-
ProviderConnectResult,
65
Subscribe,
76
SwitchNetwork,
87
WalletInfo,
@@ -17,11 +16,10 @@ import {
1716
switchNetworkForEvm,
1817
WalletTypes,
1918
} from '@rango-dev/wallets-shared';
20-
import { cosmosBlockchains, evmBlockchains } from 'rango-types';
19+
import { evmBlockchains } from 'rango-types';
2120

2221
import { metamask as metamask_instance } from './helpers';
2322
import signer from './signer';
24-
import { getAddresses, installCosmosSnap, isCosmosSnapInstalled } from './snap';
2523

2624
const WALLET = WalletTypes.META_MASK;
2725

@@ -31,29 +29,18 @@ export const config = {
3129

3230
export const getInstance = metamask_instance;
3331
export const connect: Connect = async ({ instance }) => {
34-
/*
35-
* cosmos snap (It's optional)
36-
* If the user approves to install Snap, we take the Cosmos addresses and add them to the accounts.
37-
*/
38-
await installCosmosSnap(instance);
39-
const installed = await isCosmosSnapInstalled(instance);
40-
let accounts: ProviderConnectResult[] = [];
41-
if (installed) {
42-
const addresses = await getAddresses(instance);
43-
accounts = addresses.map((item) => ({
44-
accounts: [item.address],
45-
chainId: item.chain_id,
46-
}));
47-
}
4832
/*
4933
* Note: We need to get `chainId` here, because for the first time
5034
* after opening the browser, wallet is locked, and don't give us accounts and chainId
5135
* on `check` phase, so `network` will be null. For this case we need to get chainId
5236
* whenever we are requesting accounts.
5337
*/
54-
const evm = await getEvmAccounts(instance);
55-
accounts = [...accounts, evm];
56-
return accounts;
38+
const { accounts, chainId } = await getEvmAccounts(instance);
39+
40+
return {
41+
accounts,
42+
chainId,
43+
};
5744
};
5845

5946
export const subscribe: Subscribe = subscribeToEvm;
@@ -70,8 +57,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
7057
allBlockChains
7158
) => {
7259
const evms = evmBlockchains(allBlockChains);
73-
const cosmos = cosmosBlockchains(allBlockChains);
74-
7560
return {
7661
name: 'MetaMask',
7762
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/metamask/icon.svg',
@@ -86,6 +71,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
8671
DEFAULT: 'https://metamask.io/download/',
8772
},
8873
color: '#dac7ae',
89-
supportedChains: [...evms, ...cosmos],
74+
supportedChains: evms,
9075
};
9176
};
-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import type { SignerFactory } from 'rango-types';
22

3-
import { DefaultCosmosSnapSigner } from '@rango-dev/signer-cosmos-snap';
43
import { DefaultEvmSigner } from '@rango-dev/signer-evm';
54
import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
65

76
export default function getSigners(provider: any): SignerFactory {
87
const signers = new DefaultSignerFactory();
98
signers.registerSigner(TxType.EVM, new DefaultEvmSigner(provider));
10-
signers.registerSigner(TxType.COSMOS, new DefaultCosmosSnapSigner(provider));
119

1210
return signers;
1311
}

wallets/shared/src/rango.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export enum WalletTypes {
7878
ENKRYPT = 'enkrypt',
7979
TAHO = 'taho',
8080
MY_TON_WALLET = 'mytonwallet',
81+
COSMOS_SNAP = 'cosmos-snap',
8182
}
8283

8384
export enum Networks {

0 commit comments

Comments
 (0)