Skip to content

Commit

Permalink
feat: integrate rabby wallet extension
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder authored and nikaaru committed Jun 18, 2024
1 parent 753b1e6 commit 145fb8f
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 5 deletions.
3 changes: 2 additions & 1 deletion wallets/provider-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@rango-dev/provider-metamask": "^0.34.1-next.1",
"@rango-dev/provider-okx": "^0.34.1-next.1",
"@rango-dev/provider-phantom": "^0.34.1-next.1",
"@rango-dev/provider-rabby": "^0.1.0",
"@rango-dev/provider-safe": "^0.27.1-next.1",
"@rango-dev/provider-safepal": "^0.34.1-next.1",
"@rango-dev/provider-solflare-snap": "^0.5.1-next.1",
Expand All @@ -56,4 +57,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 @@ -22,6 +22,7 @@ import * as mathwallet from '@rango-dev/provider-math-wallet';
import * as metamask from '@rango-dev/provider-metamask';
import * as okx from '@rango-dev/provider-okx';
import * as phantom from '@rango-dev/provider-phantom';
import * as rabby from '@rango-dev/provider-rabby';
import * as safe from '@rango-dev/provider-safe';
import * as safepal from '@rango-dev/provider-safepal';
import * as solflareSnap from '@rango-dev/provider-solflare-snap';
Expand Down Expand Up @@ -80,5 +81,6 @@ export const allProviders = (options?: Options) => {
taho,
braavos,
ledger,
rabby,
];
};
Empty file.
31 changes: 31 additions & 0 deletions wallets/provider-rabby/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@rango-dev/provider-rabby",
"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-rabby",
"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.1",
"rango-types": "^0.1.59"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions wallets/provider-rabby/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @rango-dev/provider-rabby
5 changes: 5 additions & 0 deletions wallets/provider-rabby/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function rabby() {
const { ethereum } = window;

return ethereum?.isRabby ? ethereum : null;
}
69 changes: 69 additions & 0 deletions wallets/provider-rabby/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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 { rabby as rabby_instance } from './helpers';
import signer from './signer';

export const config = {
type: WalletTypes.Rabby,
};

export const getInstance = rabby_instance;
export const connect: Connect = async ({ instance }) => {
/*
* 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 { 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: 'Rabby',
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/rabby/icon.svg',
installLink: {
CHROME:
'https://chromewebstore.google.com/detail/rabby-wallet/acmacodkjbdgmoleebolmdjonilkdbch',
DEFAULT: 'https://rabby.io/',
},
color: '#fff',
supportedChains: evms,
};
};
10 changes: 10 additions & 0 deletions wallets/provider-rabby/src/signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { SignerFactory } from 'rango-types';

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));
return signers;
}
11 changes: 11 additions & 0 deletions wallets/provider-rabby/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 @@ -148,6 +148,7 @@ For better user experience, wallet provider tries to connect to a wallet only wh
| Metamask | EVM | - | ✓ | - |
| OKX | EVM,Solana,Cosmos | Cosmos | ✓ | https://www.okx.com/web3 |
| Phantom | Solana,Ethereum,Polygon | Ethereum,Polygon | ✓ | - |
| Rabby | EVM | - | ✓ | https://rabby.io/ |
| Safe | EVM | - | ✓ | https://safe.global/ |
| SafePal | EVM,Solana,BTC,Tron,LTC,Doge,Aptos,TON | BTC,Tron,LTC,Doge,Aptos,TON | ✗ | https://www.safepal.com/ |
| Solflare Snap | Solana | - | ✗ | https://solflare.com/metamask |
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 @@ -81,6 +81,7 @@ export enum WalletTypes {
MY_TON_WALLET = 'mytonwallet',
SOLFLARE_SNAP = 'solflare-snap',
LEDGER = 'ledger',
Rabby = 'rabby',
}

export enum Networks {
Expand Down
33 changes: 29 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16295,7 +16295,7 @@ rango-types@^0.1.57:
resolved "https://registry.yarnpkg.com/rango-types/-/rango-types-0.1.57.tgz#0e5378ae2e4114c4c71ad0ec98b86b3966ebe765"
integrity sha512-F9bpBQovmP/GMENdFs5I4zZwbsPAHWmUCj33eIbu8ZbNa76/BmbC7nMfhViggNTXC2WHJaFsqhyukOEILU2Tlg==

rango-types@^0.1.69:
rango-types@^0.1.59, rango-types@^0.1.69:
version "0.1.69"
resolved "https://registry.yarnpkg.com/rango-types/-/rango-types-0.1.69.tgz#36a7cebc149f6775855a02353300dbff8dfe297e"
integrity sha512-q/SzeEP6E6C50TfFulzuHYLQEGbXhb3C5CuO9Ljc2IT98JOMVGf84DCXa9Clm8ChRQB99Or0uBieScYP+4jDIA==
Expand Down Expand Up @@ -17612,7 +17612,16 @@ string-format@^2.0.0:
resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b"
integrity sha512-bbEs3scLeYNXLecRRuk6uJxdXUSj6le/8rNPHChIJTn2V79aXVTR1EH2OH5zLKKoz0V02fOUKZZcw01pLUShZA==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -17704,7 +17713,14 @@ stringify-object@^5.0.0:
is-obj "^3.0.0"
is-regexp "^3.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -19075,7 +19091,7 @@ wordwrapjs@^4.0.0:
reduce-flatten "^2.0.0"
typical "^5.2.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -19093,6 +19109,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.0.1, wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 145fb8f

Please sign in to comment.