Skip to content

Commit 5ad0c40

Browse files
author
Pavel Ivanov
authored
Merge pull request #1167 from hrpalencia/dev
add new wallet (arepa wallet)
2 parents af7fa92 + 93a2bb6 commit 5ad0c40

17 files changed

+643
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"scripts": {
4545
"build:account-export": "nx run-many --target=build --projects=account-export --configuration=production",
4646
"build:all": "nx run-many --target=build --all --exclude=react,angular --configuration=production && node ./scripts/update-package-json.js",
47+
"build:arepa-wallet": "nx run-many --target=build --projects=arepa-wallet --configuration=production",
4748
"build:bitget-wallet": "nx run-many --target=build --projects=bitget-wallet --configuration=production",
4849
"build:core": "nx run-many --target=build --projects=core --configuration=production",
4950
"build:here-wallet": "nx run-many --target=build --projects=here-wallet --configuration=production",

packages/arepa-wallet/.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"@nrwl/js/babel",
5+
{
6+
"useBuiltIns": "usage"
7+
}
8+
]
9+
]
10+
}

packages/arepa-wallet/.eslintrc.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

packages/arepa-wallet/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# @near-wallet-selector/my-near-wallet
2+
3+
This is the [Arepa Wallet](https://mi.arepa.digital/) package for NEAR Wallet Selector.
4+
5+
## Installation and Usage
6+
7+
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:
8+
9+
```bash
10+
# Using Yarn
11+
yarn add near-api-js
12+
13+
# Using NPM.
14+
npm install near-api-js
15+
```
16+
```bash
17+
# Using Yarn
18+
yarn add @near-wallet-selector/arepa-wallet
19+
20+
# Using NPM.
21+
npm install @near-wallet-selector/arepa-wallet
22+
```
23+
24+
Then use it in your dApp:
25+
26+
```ts
27+
import { setupWalletSelector } from "@near-wallet-selector/core";
28+
import { setupArepaWallet } from "@near-wallet-selector/arepa-wallet";
29+
30+
// My NEAR Wallet for Wallet Selector can be setup without any params or it can take few optional params, see options below.
31+
const arepaWallet = setupArepaWallet({
32+
walletUrl: "https://develop.globaldv.tech/wallet-arepa/",
33+
iconUrl: "https://<Wallet Icon URL Here>" // optional
34+
});
35+
36+
const selector = await setupWalletSelector({
37+
network: "testnet",
38+
modules: [arepaWallet],
39+
});
40+
```
41+
42+
## Options
43+
44+
- `walletUrl` (`string?`): Wallet URL used to redirect when signing transactions. This parameter is required for custom network configuration.
45+
- `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`.
46+
- `deprecated`: (`boolean?`): Deprecated is optional. Default is `false`.
47+
- `successUrl`: (`string?`): SuccessUrl is optional. Default is `''` (empty string).
48+
- `failureUrl`: (`string?`): FailureUrl is optional. Default is `''` (empty string).
49+
50+
## Assets
51+
52+
Assets such as icons can be found in the `/assets` directory of the package. Below is an example using Webpack:
53+
54+
```ts
55+
import { setupMyNearWallet } from "@near-wallet-selector/arepa-wallet";
56+
import arepaWalletIconUrl from "@near-wallet-selector/arepa-wallet/assets/arepa-wallet-icon.png";
57+
58+
const arepaWallet = setupArepaWallet({
59+
iconUrl: arepaWalletIconUrl
60+
});
61+
```
62+
63+
## License
64+
65+
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
Loading

packages/arepa-wallet/jest.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
displayName: "arepa-wallet",
3+
preset: "../../jest.preset.js",
4+
globals: {
5+
"ts-jest": {
6+
tsconfig: "<rootDir>/tsconfig.spec.json",
7+
},
8+
},
9+
transform: {
10+
"^.+\\.[tj]sx?$": "ts-jest",
11+
},
12+
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
13+
coverageDirectory: "../../coverage/packages/arepa-wallet",
14+
};

packages/arepa-wallet/jest.config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: "arepa-wallet",
4+
preset: "../../jest.preset.js",
5+
globals: {},
6+
transform: {
7+
"^.+\\.[tj]s$": [
8+
"ts-jest",
9+
{
10+
tsconfig: "<rootDir>/tsconfig.spec.json",
11+
},
12+
],
13+
},
14+
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
15+
coverageDirectory: "../../coverage/packages/arepa-wallet",
16+
};

packages/arepa-wallet/package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@near-wallet-selector/arepa-wallet",
3+
"version": "8.9.7",
4+
"description": "Arepa Wallet package for NEAR Wallet Selector.",
5+
"keywords": [
6+
"near",
7+
"blockchain",
8+
"wallets",
9+
"dapps",
10+
"near-protocol",
11+
"near-blockchain",
12+
"wallet selector",
13+
"browser wallet",
14+
"arepa Wallet"
15+
],
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/near/wallet-selector.git"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/near/wallet-selector/issues"
22+
},
23+
"homepage": "https://github.com/near/wallet-selector/tree/main/packages/arepa-wallet",
24+
"peerDependencies": {
25+
"near-api-js": "4.0.3"
26+
}
27+
}

packages/arepa-wallet/project.json

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "arepa-wallet",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "packages/arepa-wallet/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nrwl/rollup:rollup",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/packages/arepa-wallet",
12+
"tsConfig": "packages/arepa-wallet/tsconfig.lib.json",
13+
"project": "packages/arepa-wallet/package.json",
14+
"entryFile": "packages/arepa-wallet/src/index.ts",
15+
"buildableProjectDepsInPackageJsonType": "dependencies",
16+
"compiler": "babel",
17+
"format": ["esm", "cjs"],
18+
"assets": [
19+
{
20+
"glob": "packages/arepa-wallet/README.md",
21+
"input": ".",
22+
"output": "."
23+
},
24+
{
25+
"glob": "packages/arepa-wallet/assets/*",
26+
"input": ".",
27+
"output": "assets"
28+
}
29+
]
30+
}
31+
},
32+
"lint": {
33+
"executor": "@nx/linter:eslint",
34+
"outputs": ["{options.outputFile}"],
35+
"options": {
36+
"lintFilePatterns": ["packages/arepa-wallet/**/*.ts"]
37+
}
38+
},
39+
"test": {
40+
"executor": "@nx/jest:jest",
41+
"outputs": ["{workspaceRoot}/coverage/packages/arepa-wallet"],
42+
"options": {
43+
"jestConfig": "packages/arepa-wallet/jest.config.ts",
44+
"passWithNoTests": true
45+
}
46+
},
47+
"deploy": {
48+
"executor": "ngx-deploy-npm:deploy",
49+
"options": {
50+
"access": "public"
51+
},
52+
"dependsOn": ["^deploy"]
53+
}
54+
},
55+
"tags": ["browser-wallet"]
56+
}

packages/arepa-wallet/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { setupArepaWallet } from "./lib/arepa-wallet";
2+
export type { ArepaWalletParams } from "./lib/arepa-wallet";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* eslint-disable @nx/enforce-module-boundaries */
2+
import type {
3+
Near,
4+
WalletConnection,
5+
ConnectedWalletAccount,
6+
} from "near-api-js";
7+
import type { AccountView } from "near-api-js/lib/providers/provider";
8+
import { mock } from "jest-mock-extended";
9+
10+
import { mockWallet } from "../../../core/src/lib/testUtils";
11+
import type { MockWalletDependencies } from "../../../core/src/lib/testUtils";
12+
import type { BrowserWallet } from "../../../core/src/lib/wallet";
13+
14+
const createArepaWallet = async (deps: MockWalletDependencies = {}) => {
15+
const walletConnection = mock<WalletConnection>();
16+
const account = mock<ConnectedWalletAccount>({
17+
connection: {
18+
signer: {
19+
getPublicKey: jest.fn().mockReturnValue(""),
20+
},
21+
},
22+
});
23+
24+
jest.mock("near-api-js", () => {
25+
const module = jest.requireActual("near-api-js");
26+
return {
27+
...module,
28+
connect: jest.fn().mockResolvedValue(mock<Near>()),
29+
WalletConnection: jest.fn().mockReturnValue(walletConnection),
30+
};
31+
});
32+
33+
walletConnection.isSignedIn.calledWith().mockReturnValue(true);
34+
walletConnection.getAccountId
35+
.calledWith()
36+
.mockReturnValue("test-account.testnet");
37+
walletConnection.account.calledWith().mockReturnValue(account);
38+
// @ts-ignore
39+
// near-api-js marks this method as protected.
40+
// TODO: return value instead of null
41+
account.signAndSendTransaction.calledWith().mockReturnValue(null);
42+
account.state.calledWith().mockResolvedValue(
43+
mock<AccountView>({
44+
amount: "1000000000000000000000000",
45+
})
46+
);
47+
48+
// eslint-disable-next-line @typescript-eslint/no-var-requires
49+
const { setupArepaWallet } = require("./arepa-wallet");
50+
const { wallet } = await mockWallet<BrowserWallet>(setupArepaWallet(), deps);
51+
52+
return {
53+
nearApiJs: require("near-api-js"),
54+
wallet,
55+
walletConnection,
56+
account,
57+
};
58+
};
59+
60+
afterEach(() => {
61+
jest.resetModules();
62+
});
63+
64+
describe("signIn", () => {
65+
it("sign into near wallet", async () => {
66+
const { wallet, nearApiJs } = await createArepaWallet();
67+
68+
await wallet.signIn({ contractId: "test.testnet" });
69+
70+
expect(nearApiJs.connect).toHaveBeenCalled();
71+
});
72+
});
73+
74+
describe("signOut", () => {
75+
it("sign out of near wallet", async () => {
76+
const { wallet, walletConnection } = await createArepaWallet();
77+
78+
await wallet.signIn({ contractId: "test.testnet" });
79+
await wallet.signOut();
80+
81+
expect(walletConnection.signOut).toHaveBeenCalled();
82+
});
83+
});
84+
85+
describe("getAccounts", () => {
86+
it("returns array of accounts", async () => {
87+
const { wallet, walletConnection } = await createArepaWallet();
88+
89+
await wallet.signIn({ contractId: "test.testnet" });
90+
const result = await wallet.getAccounts();
91+
92+
expect(walletConnection.getAccountId).toHaveBeenCalled();
93+
expect(result).toEqual([
94+
{ accountId: "test-account.testnet", publicKey: "" },
95+
]);
96+
});
97+
});
98+
99+
describe("signAndSendTransaction", () => {
100+
// TODO: Figure out why imports to core are returning undefined.
101+
it("signs and sends transaction", async () => {
102+
const { wallet, walletConnection, account } = await createArepaWallet();
103+
104+
await wallet.signIn({ contractId: "test.testnet" });
105+
const result = await wallet.signAndSendTransaction({
106+
receiverId: "guest-book.testnet",
107+
actions: [],
108+
});
109+
110+
expect(walletConnection.account).toHaveBeenCalled();
111+
// near-api-js marks this method as protected.
112+
// @ts-ignore
113+
expect(account.signAndSendTransaction).toHaveBeenCalled();
114+
// @ts-ignore
115+
expect(account.signAndSendTransaction).toBeCalledWith({
116+
actions: [],
117+
receiverId: "guest-book.testnet",
118+
});
119+
expect(result).toEqual(null);
120+
});
121+
});

0 commit comments

Comments
 (0)