-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3fee4b
commit 79290a5
Showing
17 changed files
with
643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nrwl/js/babel", | ||
{ | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "^1.0.0 || ^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.