Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new wallet (arepa wallet) #1167

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"scripts": {
"build:account-export": "nx run-many --target=build --projects=account-export --configuration=production",
"build:all": "nx run-many --target=build --all --exclude=react,angular --configuration=production && node ./scripts/update-package-json.js",
"build:arepa-wallet": "nx run-many --target=build --projects=arepa-wallet --configuration=production",
"build:bitget-wallet": "nx run-many --target=build --projects=bitget-wallet --configuration=production",
"build:core": "nx run-many --target=build --projects=core --configuration=production",
"build:here-wallet": "nx run-many --target=build --projects=here-wallet --configuration=production",
Expand Down
10 changes: 10 additions & 0 deletions packages/arepa-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/arepa-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": {}
}
]
}
65 changes: 65 additions & 0 deletions packages/arepa-wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @near-wallet-selector/my-near-wallet

This is the [Arepa Wallet](https://mi.arepa.digital/) package for NEAR Wallet Selector.

## 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/arepa-wallet

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

Then use it in your dApp:

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

// My NEAR Wallet for Wallet Selector can be setup without any params or it can take few optional params, see options below.
const arepaWallet = setupArepaWallet({
walletUrl: "https://develop.globaldv.tech/wallet-arepa/",
iconUrl: "https://<Wallet Icon URL Here>" // optional
});

const selector = await setupWalletSelector({
network: "testnet",
modules: [arepaWallet],
});
```

## Options

- `walletUrl` (`string?`): Wallet URL used to redirect when signing transactions. This parameter is required for custom network configuration.
- `iconUrl`: (`string?`): Image URL for the icon shown in the modal. This can also be a relative path or base64 encoded image. Defaults to `./assets/arepa-wallet-icon.png`.
- `deprecated`: (`boolean?`): Deprecated is optional. Default is `false`.
- `successUrl`: (`string?`): SuccessUrl is optional. Default is `''` (empty string).
- `failureUrl`: (`string?`): FailureUrl is optional. Default is `''` (empty string).

## Assets

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

```ts
import { setupMyNearWallet } from "@near-wallet-selector/arepa-wallet";
import arepaWalletIconUrl from "@near-wallet-selector/arepa-wallet/assets/arepa-wallet-icon.png";

const arepaWallet = setupArepaWallet({
iconUrl: arepaWalletIconUrl
});
```

## License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions packages/arepa-wallet/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: "arepa-wallet",
preset: "../../jest.preset.js",
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.spec.json",
},
},
transform: {
"^.+\\.[tj]sx?$": "ts-jest",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/packages/arepa-wallet",
};
16 changes: 16 additions & 0 deletions packages/arepa-wallet/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: "arepa-wallet",
preset: "../../jest.preset.js",
globals: {},
transform: {
"^.+\\.[tj]s$": [
"ts-jest",
{
tsconfig: "<rootDir>/tsconfig.spec.json",
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/packages/arepa-wallet",
};
27 changes: 27 additions & 0 deletions packages/arepa-wallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@near-wallet-selector/arepa-wallet",
"version": "8.9.7",
"description": "Arepa Wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
"blockchain",
"wallets",
"dapps",
"near-protocol",
"near-blockchain",
"wallet selector",
"browser wallet",
"arepa 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/arepa-wallet",
"peerDependencies": {
"near-api-js": "4.0.3"
}
}
56 changes: 56 additions & 0 deletions packages/arepa-wallet/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "arepa-wallet",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/arepa-wallet/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/arepa-wallet",
"tsConfig": "packages/arepa-wallet/tsconfig.lib.json",
"project": "packages/arepa-wallet/package.json",
"entryFile": "packages/arepa-wallet/src/index.ts",
"buildableProjectDepsInPackageJsonType": "dependencies",
"compiler": "babel",
"format": ["esm", "cjs"],
"assets": [
{
"glob": "packages/arepa-wallet/README.md",
"input": ".",
"output": "."
},
{
"glob": "packages/arepa-wallet/assets/*",
"input": ".",
"output": "assets"
}
]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/arepa-wallet/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/packages/arepa-wallet"],
"options": {
"jestConfig": "packages/arepa-wallet/jest.config.ts",
"passWithNoTests": true
}
},
"deploy": {
"executor": "ngx-deploy-npm:deploy",
"options": {
"access": "public"
},
"dependsOn": ["^deploy"]
}
},
"tags": ["browser-wallet"]
}
2 changes: 2 additions & 0 deletions packages/arepa-wallet/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { setupArepaWallet } from "./lib/arepa-wallet";
export type { ArepaWalletParams } from "./lib/arepa-wallet";
121 changes: 121 additions & 0 deletions packages/arepa-wallet/src/lib/arepa-wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* eslint-disable @nx/enforce-module-boundaries */
import type {
Near,
WalletConnection,
ConnectedWalletAccount,
} from "near-api-js";
import type { AccountView } from "near-api-js/lib/providers/provider";
import { mock } from "jest-mock-extended";

import { mockWallet } from "../../../core/src/lib/testUtils";
import type { MockWalletDependencies } from "../../../core/src/lib/testUtils";
import type { BrowserWallet } from "../../../core/src/lib/wallet";

const createArepaWallet = async (deps: MockWalletDependencies = {}) => {
const walletConnection = mock<WalletConnection>();
const account = mock<ConnectedWalletAccount>({
connection: {
signer: {
getPublicKey: jest.fn().mockReturnValue(""),
},
},
});

jest.mock("near-api-js", () => {
const module = jest.requireActual("near-api-js");
return {
...module,
connect: jest.fn().mockResolvedValue(mock<Near>()),
WalletConnection: jest.fn().mockReturnValue(walletConnection),
};
});

walletConnection.isSignedIn.calledWith().mockReturnValue(true);
walletConnection.getAccountId
.calledWith()
.mockReturnValue("test-account.testnet");
walletConnection.account.calledWith().mockReturnValue(account);
// @ts-ignore
// near-api-js marks this method as protected.
// TODO: return value instead of null
account.signAndSendTransaction.calledWith().mockReturnValue(null);
account.state.calledWith().mockResolvedValue(
mock<AccountView>({
amount: "1000000000000000000000000",
})
);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { setupArepaWallet } = require("./arepa-wallet");
const { wallet } = await mockWallet<BrowserWallet>(setupArepaWallet(), deps);

return {
nearApiJs: require("near-api-js"),
wallet,
walletConnection,
account,
};
};

afterEach(() => {
jest.resetModules();
});

describe("signIn", () => {
it("sign into near wallet", async () => {
const { wallet, nearApiJs } = await createArepaWallet();

await wallet.signIn({ contractId: "test.testnet" });

expect(nearApiJs.connect).toHaveBeenCalled();
});
});

describe("signOut", () => {
it("sign out of near wallet", async () => {
const { wallet, walletConnection } = await createArepaWallet();

await wallet.signIn({ contractId: "test.testnet" });
await wallet.signOut();

expect(walletConnection.signOut).toHaveBeenCalled();
});
});

describe("getAccounts", () => {
it("returns array of accounts", async () => {
const { wallet, walletConnection } = await createArepaWallet();

await wallet.signIn({ contractId: "test.testnet" });
const result = await wallet.getAccounts();

expect(walletConnection.getAccountId).toHaveBeenCalled();
expect(result).toEqual([
{ accountId: "test-account.testnet", publicKey: "" },
]);
});
});

describe("signAndSendTransaction", () => {
// TODO: Figure out why imports to core are returning undefined.
it("signs and sends transaction", async () => {
const { wallet, walletConnection, account } = await createArepaWallet();

await wallet.signIn({ contractId: "test.testnet" });
const result = await wallet.signAndSendTransaction({
receiverId: "guest-book.testnet",
actions: [],
});

expect(walletConnection.account).toHaveBeenCalled();
// near-api-js marks this method as protected.
// @ts-ignore
expect(account.signAndSendTransaction).toHaveBeenCalled();
// @ts-ignore
expect(account.signAndSendTransaction).toBeCalledWith({
actions: [],
receiverId: "guest-book.testnet",
});
expect(result).toEqual(null);
});
});
Loading
Loading