Skip to content

Commit

Permalink
add rabby wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbyweb3team001 committed Aug 20, 2024
1 parent c083610 commit d782158
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/rabby-wallet/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/js/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions packages/rabby-wallet/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
70 changes: 70 additions & 0 deletions packages/rabby-wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# @near-wallet-selector/rabby-wallet

This is the [Rabby Wallet](https://chromewebstore.google.com/detail/rabby-wallet/acmacodkjbdgmoleebolmdjonilkdbch) package for NEAR Wallet Selector.

## Install Rabby Wallet

- [Chrome](https://chromewebstore.google.com/detail/rabby-wallet/acmacodkjbdgmoleebolmdjonilkdbch)


## Installation and Usage

The easiest way to use this package is to install it from the NPM registry, this package requires `near-api-js` v1.0.0 or above:

```bash
# Using Yarn
yarn add near-api-js

# Using NPM.
npm install near-api-js
```
```bash
# Using Yarn
yarn add @near-wallet-selector/rabby-wallet

# Using NPM.
npm install @near-wallet-selector/rabby-wallet
```

Then use it in your dApp:

```ts
import { setupWalletSelector } from "@near-wallet-selector/core";
import { setupRabbyWallet } from "@near-wallet-selector/rabby-wallet";

// Rabby Wallet for Wallet Selector can be setup without any params or it can take few optional params, see options below.
const rabbyWallet = setupRabbyWallet({
iconUrl: "https://<Wallet Icon URL Here>" // optional
});

const selector = await setupWalletSelector({
network: "mainnet", // Rabby Wallet only supports NEAR Mainnet at the moment.
modules: [rabbyWallet],
});
```

## Options

- `iconUrl`: (`string?`): Image URL for the icon shown in the modal. This can also be a relative path or base64 encoded image. Defaults is `./assets/rabby-wallet.png`.
- `deprecated`: (`boolean?`): Deprecated is optional. Default is `false`.

## Assets

Assets such as icons can be found in the `/assets` directory of the package. Below is an example using Webpack:

```ts
import { setupRabbyWallet } from "@near-wallet-selector/rabby-wallet";
import rabbyIconUrl from "@near-wallet-selector/rabby-wallet/assets/rabby-wallet.png";

const rabbyWallet = setupRabbyWallet({
iconUrl: rabbyIconUrl
});
```

## Tip

Rabby Wallet only supports NEAR Mainnet at the moment.

## License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
Binary file added packages/rabby-wallet/assets/rabby-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions packages/rabby-wallet/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: "rabby-wallet",
preset: "../../jest.preset.js",
globals: {},
transform: {
"^.+\\.[tj]s$": [
"ts-jest",
{
tsconfig: "<rootDir>/tsconfig.spec.json",
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/packages/rabby-wallet",
};
24 changes: 24 additions & 0 deletions packages/rabby-wallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@near-wallet-selector/rabby-wallet",
"version": "8.9.12",
"description": "rabby Wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
"blockchain",
"wallets",
"dapps",
"near-protocol",
"near-blockchain",
"wallet selector",
"injected wallet",
"Rabby wallet"
],
"repository": {
"type": "git",
"url": "https://github.com/near/wallet-selector.git"
},
"bugs": {
"url": "https://github.com/near/wallet-selector/issues"
},
"homepage": "https://github.com/near/wallet-selector/tree/main/packages/rabby-wallet"
}
56 changes: 56 additions & 0 deletions packages/rabby-wallet/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "rabby-wallet",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/rabby-wallet/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/rabby-wallet",
"tsConfig": "packages/rabby-wallet/tsconfig.lib.json",
"project": "packages/rabby-wallet/package.json",
"entryFile": "packages/rabby-wallet/src/index.ts",
"buildableProjectDepsInPackageJsonType": "dependencies",
"compiler": "babel",
"format": ["esm", "cjs"],
"assets": [
{
"glob": "packages/rabby-wallet/README.md",
"input": ".",
"output": "."
},
{
"glob": "packages/rabby-wallet/assets/*",
"input": ".",
"output": "assets"
}
]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/rabby-wallet/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/packages/rabby-wallet"],
"options": {
"jestConfig": "packages/rabby-wallet/jest.config.ts",
"passWithNoTests": true
}
},
"deploy": {
"executor": "ngx-deploy-npm:deploy",
"options": {
"access": "public"
},
"dependsOn": ["^deploy"]
}
},
"tags": ["injected-wallet"]
}
2 changes: 2 additions & 0 deletions packages/rabby-wallet/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { setupRabbyWallet } from "./lib/rabby-wallet";
export type { RabbyWalletParams } from "./lib/rabby-wallet";
1 change: 1 addition & 0 deletions packages/rabby-wallet/src/lib/icon.ts

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions packages/rabby-wallet/src/lib/injected-rabby-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
export interface AccessKey {
publicKey: string;
secretKey: string;
}

interface RequestSignInResponse {
accessKey: AccessKey;
accountId: string;
error: string | { type: string };
}

export type SignOutResponse = true | { error: string | { type: string } };

interface RequestSignInParams {
contractId?: string;
methodNames?: Array<string>;
}

interface Action {
methodName: string;
args: object;
gas: string;
deposit: string;
}

interface SignAndSendTransactionParams {
receiverId: string;
actions: Array<Action>;
}

export interface SignAndSendTransactionResponse {
method: string;
txHash: string;
code: number;
}

interface Transaction {
receiverId: string;
actions: Array<Action>;
}

interface RequestSignTransactionsParams {
transactions: Array<Transaction>;
}

interface RequestSignTransactionsResponse {
txs: Array<{
signedTx: string;
}>;
}

export interface RabbyEvents {
signIn: () => void;
signOut: () => void;
accountChanged: (changedAccountId: string) => void;
}

export interface InjectedRabby {
getAccountId: () => string | null;
requestSignIn: (
params: RequestSignInParams
) => Promise<RequestSignInResponse>;
signOut: () => Promise<SignOutResponse>;
isSignedIn: () => boolean;
on: <Event extends keyof RabbyEvents>(
event: Event,
callback: RabbyEvents[Event]
) => void;
signTransaction: (params: SignAndSendTransactionParams) => Promise<string>;
requestSignTransactions: (
params: RequestSignTransactionsParams
) => Promise<RequestSignTransactionsResponse>;
}
Loading

0 comments on commit d782158

Please sign in to comment.