Skip to content

Commit

Permalink
feat: integrate tomo wallet extension
Browse files Browse the repository at this point in the history
  • Loading branch information
RanGojo authored and RyukTheCoder committed Jun 19, 2024
1 parent e854945 commit 9f0f065
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 1 deletion.
1 change: 1 addition & 0 deletions global-wallets-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ declare global {
bitkeep: any;
mytonwallet: any;
offlineSigner: any;
tomo_evm: any;
}
}
3 changes: 2 additions & 1 deletion wallets/provider-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@rango-dev/provider-solflare-snap": "^0.5.1-next.2",
"@rango-dev/provider-taho": "^0.34.1-next.2",
"@rango-dev/provider-tokenpocket": "^0.34.1-next.2",
"@rango-dev/provider-tomo": "^0.1.0",
"@rango-dev/provider-tron-link": "^0.34.1-next.2",
"@rango-dev/provider-trustwallet": "^0.34.1-next.2",
"@rango-dev/provider-walletconnect-2": "^0.27.1-next.2",
Expand All @@ -57,4 +58,4 @@
"publishConfig": {
"access": "public"
}
}
}
2 changes: 2 additions & 0 deletions wallets/provider-all/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as safepal from '@rango-dev/provider-safepal';
import * as solflareSnap from '@rango-dev/provider-solflare-snap';
import * as taho from '@rango-dev/provider-taho';
import * as tokenpocket from '@rango-dev/provider-tokenpocket';
import * as tomo from '@rango-dev/provider-tomo';
import * as tronLink from '@rango-dev/provider-tron-link';
import * as trustwallet from '@rango-dev/provider-trustwallet';
import * as walletconnect2 from '@rango-dev/provider-walletconnect-2';
Expand Down Expand Up @@ -75,6 +76,7 @@ export const allProviders = (options?: Options) => {
mathwallet,
okx,
tokenpocket,
tomo,
halo,
leapCosmos,
frontier,
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions wallets/provider-tomo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@rango-dev/provider-tomo",
"version": "0.1.0",
"license": "MIT",
"type": "module",
"source": "./src/index.ts",
"main": "./dist/index.js",
"exports": {
".": "./dist/index.js"
},
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"build": "node ../../scripts/build/command.mjs --path wallets/provider-tomo",
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
"clean": "rimraf dist",
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
},
"dependencies": {
"@rango-dev/signer-evm": "^0.27.2-next.0",
"@rango-dev/wallets-shared": "^0.34.1-next.0",
"rango-types": "^0.1.69"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions wallets/provider-tomo/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @rango-dev/provider-tomo
8 changes: 8 additions & 0 deletions wallets/provider-tomo/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function tomo() {
const { tomo_evm } = window;
if (tomo_evm) {
return tomo_evm;
}

return null;
}
67 changes: 67 additions & 0 deletions wallets/provider-tomo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type {
CanEagerConnect,
CanSwitchNetwork,
Connect,
Subscribe,
SwitchNetwork,
WalletInfo,
} from '@rango-dev/wallets-shared';
import type { BlockchainMeta, SignerFactory } from 'rango-types';

import {
canEagerlyConnectToEvm,
canSwitchNetworkToEvm,
getEvmAccounts,
subscribeToEvm,
switchNetworkForEvm,
WalletTypes,
} from '@rango-dev/wallets-shared';
import { evmBlockchains } from 'rango-types';

import { tomo as tomo_instance } from './helpers';
import signer from './signer';

const WALLET = WalletTypes.TOMO;

export const config = {
type: WALLET,
};

export const getInstance = tomo_instance;
export const connect: Connect = async ({ instance }) => {
const { accounts, chainId } = await getEvmAccounts(instance);

return {
accounts,
chainId,
};
};

export const subscribe: Subscribe = subscribeToEvm;

export const switchNetwork: SwitchNetwork = switchNetworkForEvm;

export const canSwitchNetworkTo: CanSwitchNetwork = canSwitchNetworkToEvm;

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

export const canEagerConnect: CanEagerConnect = canEagerlyConnectToEvm;

export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
allBlockChains
) => {
const evms = evmBlockchains(allBlockChains);
return {
name: 'Tomo',
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/tomo/icon.svg',
color: '#b2dbff',
installLink: {
CHROME:
'https://chromewebstore.google.com/detail/tomo-wallet/pfccjkejcgoppjnllalolplgogenfojk?hl=en',
BRAVE:
'https://chromewebstore.google.com/detail/tomo-wallet/pfccjkejcgoppjnllalolplgogenfojk?hl=en',
DEFAULT: 'https://tomo.inc/',
},
supportedChains: evms,
};
};
12 changes: 12 additions & 0 deletions wallets/provider-tomo/src/signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { SignerFactory } from 'rango-types';

import { DefaultEvmSigner } from '@rango-dev/signer-evm';
import { getNetworkInstance, Networks } from '@rango-dev/wallets-shared';
import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';

export default function getSigners(provider: any): SignerFactory {
const ethProvider = getNetworkInstance(provider, Networks.ETHEREUM);
const signers = new DefaultSignerFactory();
signers.registerSigner(TxType.EVM, new DefaultEvmSigner(ethProvider));
return signers;
}
11 changes: 11 additions & 0 deletions wallets/provider-tomo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"extends": "../../tsconfig.lib.json",
"include": ["src", "types", "../../global-wallets-env.d.ts"],
"compilerOptions": {
"outDir": "dist",
"rootDir": "./src",
"lib": ["dom", "esnext"]
// match output dir to input dir. e.g. dist/index instead of dist/src/index
}
}
1 change: 1 addition & 0 deletions wallets/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ For better user experience, wallet provider tries to connect to a wallet only wh
| Station | Terra Classic, Terra | - | ✗ | https://station.terra.money/ |
| Taho | ETH,Polygon,Arbitrum,Arbitrum,Avax,Binance,Fantom | Fantom | ✗ | https://taho.xyz/ |
| TokenPocket | EVM | - | ✓ | https://extension.tokenpocket.pro/#/ |
| Tomo | EVM,Cosmos,BTC | Cosmos,BTC | ✓ | https://tomo.inc/ |
| TronLink | Tron | - | ✗ | - |
| Trust Wallet | EVM,Solana | Solana | ✓ | https://trustwallet.com/ |
| Wallet Connect | Evm,Solana,Cosmos | Solana,Cosmos | ✗ | - |
Expand Down
1 change: 1 addition & 0 deletions wallets/shared/src/rango.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export enum WalletTypes {
SOLFLARE_SNAP = 'solflare-snap',
LEDGER = 'ledger',
Rabby = 'rabby',
TOMO = 'tomo',
}

export enum Networks {
Expand Down

0 comments on commit 9f0f065

Please sign in to comment.