Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasackermn committed Nov 29, 2023
1 parent 97fa94c commit fa454c8
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 95 deletions.
58 changes: 0 additions & 58 deletions signers/signer-cosmos-snap/CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion signers/signer-cosmos-snap/readme.md

This file was deleted.

1 change: 0 additions & 1 deletion signers/signer-cosmos-snap/src/index.ts

This file was deleted.

51 changes: 51 additions & 0 deletions wallets/provider-cosmos-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# [0.14.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.14.0) (2023-08-03)



# [0.13.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.13.0) (2023-08-01)



# [0.9.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.9.0) (2023-07-31)



# [0.7.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.7.0) (2023-07-11)



# [0.6.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.6.0) (2023-07-11)


### Reverts

* Revert "support for rango-types cjs format" ([ed4e050](https://github.com/rango-exchange/rango-client/commit/ed4e050bfc0dcde7aeffa6b0d73b02080a5721eb))
* Revert "support for rango-types cjs format" ([4f5f55f](https://github.com/rango-exchange/rango-client/commit/4f5f55f96e8daa329588b932b19c291c30f339c4))



# [0.5.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.5.0) (2023-05-31)



# [0.4.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.4.0) (2023-05-31)



# [0.3.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.3.0) (2023-05-30)



# [0.2.0](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.2.0) (2023-05-30)



## [0.1.14](https://github.com/rango-exchange/rango-client/compare/[email protected]@0.1.14) (2023-05-15)


### Bug Fixes

* update rango-types and fix notification bugs ([993f185](https://github.com/rango-exchange/rango-client/commit/993f185e0b8c5e5e15a2c65ba2d85d1f9c8daa90))



Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rango-dev/signer-cosmos-snap",
"version": "0.17.0",
"name": "@rango-dev/provider-cosmos-snap",
"version": "0.17.1-next.1",
"license": "MIT",
"type": "module",
"module": "./dist/index.js",
Expand All @@ -14,15 +14,13 @@
"src"
],
"scripts": {
"build": "node ../../scripts/build/command.mjs --path signers/signer-cosmos-snap",
"build": "node ../../scripts/build/command.mjs --path wallets/provider-cosmos-snap",
"clean": "rimraf dist",
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore",
"test": "vitest",
"test:watch": "vitest --watch",
"test:coverage": "vitest run --coverage"
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
},
"dependencies": {
"@rango-dev/wallets-shared": "^0.17.1-next.1",
"rango-types": "^0.1.46",
"@cosmjs/amino": "^0.31.3",
"@cosmjs/proto-signing": "^0.30.1",
Expand Down
1 change: 1 addition & 0 deletions wallets/provider-cosmos-snap/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @rango-dev/provider-cosmos-snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
export const DEFAULT_SNAP_ID = 'npm:@cosmsnap/snap';
import { getCoinbaseInstance } from '@rango-dev/wallets-shared';

import { DEFAULT_SNAP_ID } from './signers/helpers';

export function metamask() {
const isCoinbaseWalletAvailable = !!getCoinbaseInstance();
const { ethereum } = window;

// Some wallets overriding the metamask. So we need to get it properly.
if (isCoinbaseWalletAvailable) {
// Getting intance from overrided structure from coinbase.
return getCoinbaseInstance('metamask');
}
if (!!ethereum && ethereum.isMetaMask) {
return ethereum;
}

return null;
}

export const isCosmosSnapInstalled = async (instance: any) => {
const result = await instance.request({ method: 'wallet_getSnaps' });
Expand Down
82 changes: 82 additions & 0 deletions wallets/provider-cosmos-snap/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type {
CanEagerConnect,
CanSwitchNetwork,
Connect,
ProviderConnectResult,
Subscribe,
WalletInfo,
} from '@rango-dev/wallets-shared';
import type { BlockchainMeta, SignerFactory } from 'rango-types';

import {
canEagerlyConnectToEvm,
subscribeToEvm,
WalletTypes,
} from '@rango-dev/wallets-shared';
import { cosmosBlockchains } from 'rango-types';

import {
getAddresses,
installCosmosSnap,
isCosmosSnapInstalled,
metamask as metamask_instance,
} from './helpers';
import signer from './signer';

const WALLET = WalletTypes.COSMOS_SNAP;

export const config = {
type: WALLET,
};

export const getInstance = metamask_instance;
export const connect: Connect = async ({ instance }) => {
/*
* cosmos snap (It's optional)
* If the user approves to install Snap, we take the Cosmos addresses and add them to the accounts.
*/
await installCosmosSnap(instance);
const installed = await isCosmosSnapInstalled(instance);
let accounts: ProviderConnectResult[] = [];
if (installed) {
const addresses = await getAddresses(instance);
accounts = addresses.map((item) => ({
accounts: [item.address],
chainId: item.chain_id,
}));
}
if (!accounts.length) {
throw new Error('You have rejected to install cosmos-snap');
}
return accounts;
};

export const subscribe: Subscribe = subscribeToEvm;

export const canSwitchNetworkTo: CanSwitchNetwork = () => false;

export const getSigners: (provider: any) => SignerFactory = signer;

export const canEagerConnect: CanEagerConnect = canEagerlyConnectToEvm;

export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
allBlockChains
) => {
const cosmos = cosmosBlockchains(allBlockChains);
return {
name: 'Cosmos Snap',
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/metamask/icon.svg',
installLink: {
CHROME:
'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en',
BRAVE:
'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en',

FIREFOX: 'https://addons.mozilla.org/en-US/firefox/addon/ether-metamask',
EDGE: 'https://microsoftedge.microsoft.com/addons/detail/metamask/ejbalbakoplchlghecdalmeeeajnimhm?hl=en-US',
DEFAULT: 'https://metamask.io/download/',
},
color: '#dac7ae',
supportedChains: cosmos,
};
};
11 changes: 11 additions & 0 deletions wallets/provider-cosmos-snap/src/signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { SignerFactory } from 'rango-types';

import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';

import StarknetSigner from './signers/cosmos';

export default function getSigners(provider: any): SignerFactory {
const signers = new DefaultSignerFactory();
signers.registerSigner(TxType.STARKNET, new StarknetSigner(provider));
return signers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { GenericSigner } from 'rango-types';
import type { CosmosTransaction } from 'rango-types/lib/api/main';

import { DEFAULT_SNAP_ID, executeTransaction } from './helper';
import { DEFAULT_SNAP_ID, executeTransaction } from './helpers';

export class DefaultCosmosSnapSigner
implements GenericSigner<CosmosTransaction>
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions wallets/provider-cosmos-snap/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface AccContract {
addressSalt: string;
publicKey: string; // in hex
address: string; // in hex
addressIndex: number;
derivationPath: string;
deployTxnHash: string; // in hex
chainId: string; // in hex
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"extends": "../../tsconfig.lib.json",
"include": ["src", "types"],
"include": ["src", "types", "../../global-wallets-env.d.ts"],
"compilerOptions": {
"outDir": "dist",
"rootDir": "./src",
Expand Down
31 changes: 8 additions & 23 deletions wallets/provider-metamask/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
CanEagerConnect,
CanSwitchNetwork,
Connect,
ProviderConnectResult,
Subscribe,
SwitchNetwork,
WalletInfo,
Expand All @@ -17,11 +16,10 @@ import {
switchNetworkForEvm,
WalletTypes,
} from '@rango-dev/wallets-shared';
import { cosmosBlockchains, evmBlockchains } from 'rango-types';
import { evmBlockchains } from 'rango-types';

import { metamask as metamask_instance } from './helpers';
import signer from './signer';
import { getAddresses, installCosmosSnap, isCosmosSnapInstalled } from './snap';

const WALLET = WalletTypes.META_MASK;

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

export const getInstance = metamask_instance;
export const connect: Connect = async ({ instance }) => {
/*
* cosmos snap (It's optional)
* If the user approves to install Snap, we take the Cosmos addresses and add them to the accounts.
*/
await installCosmosSnap(instance);
const installed = await isCosmosSnapInstalled(instance);
let accounts: ProviderConnectResult[] = [];
if (installed) {
const addresses = await getAddresses(instance);
accounts = addresses.map((item) => ({
accounts: [item.address],
chainId: item.chain_id,
}));
}
/*
* Note: We need to get `chainId` here, because for the first time
* after opening the browser, wallet is locked, and don't give us accounts and chainId
* on `check` phase, so `network` will be null. For this case we need to get chainId
* whenever we are requesting accounts.
*/
const evm = await getEvmAccounts(instance);
accounts = [...accounts, evm];
return accounts;
const { accounts, chainId } = await getEvmAccounts(instance);

return {
accounts,
chainId,
};
};

export const subscribe: Subscribe = subscribeToEvm;
Expand All @@ -70,8 +57,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
allBlockChains
) => {
const evms = evmBlockchains(allBlockChains);
const cosmos = cosmosBlockchains(allBlockChains);

return {
name: 'MetaMask',
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/metamask/icon.svg',
Expand All @@ -86,6 +71,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
DEFAULT: 'https://metamask.io/download/',
},
color: '#dac7ae',
supportedChains: [...evms, ...cosmos],
supportedChains: evms,
};
};
2 changes: 0 additions & 2 deletions wallets/provider-metamask/src/signer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { SignerFactory } from 'rango-types';

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

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

return signers;
}
1 change: 1 addition & 0 deletions wallets/shared/src/rango.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export enum WalletTypes {
ENKRYPT = 'enkrypt',
TAHO = 'taho',
MY_TON_WALLET = 'mytonwallet',
COSMOS_SNAP = 'cosmos-snap',
}

export enum Networks {
Expand Down

0 comments on commit fa454c8

Please sign in to comment.