From 391413068055e4842e9677955735c081ba8744ae Mon Sep 17 00:00:00 2001 From: Lewis Barnes Date: Tue, 29 Mar 2022 15:34:22 +0100 Subject: [PATCH 1/5] Updated configuration files. --- README.md | 10 +++++----- nx.json | 2 +- package.json | 4 ++-- packages/near-wallet-selector/package.json | 4 ++-- tsconfig.base.json | 2 +- workspace.json | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f75d39fcf..7d9463196 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,20 @@ The easiest way to use `near-wallet-selector` is to install it from the NPM regi ```bash # Using Yarn -yarn add near-wallet-selector +yarn add @near-wallet-selector/core # Using NPM. -npm install near-wallet-selector +npm install @near-wallet-selector/core ``` Then use it in your dApp: ```ts -import NearWalletSelector from "near-wallet-selector"; +import NearWalletSelector from "@near-wallet-selector/core"; const selector = await NearWalletSelector.init({ wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], - networkId: "testnet", + network: "testnet", contract: { contractId: "guest-book.testnet" }, }); ``` @@ -70,7 +70,7 @@ Initialises the selector using the configured options before rendering the UI. I ```ts await NearWalletSelector.init({ wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], - networkId: "testnet", + network: "testnet", contract: { contractId: "guest-book.testnet" }, }); ``` diff --git a/nx.json b/nx.json index af2e85f2e..50c2b108d 100644 --- a/nx.json +++ b/nx.json @@ -1,6 +1,6 @@ { "extends": "@nrwl/workspace/presets/core.json", - "npmScope": "near-wallet-selector", + "npmScope": "@near-wallet-selector", "workspaceLayout": { "appsDir": "examples", "libsDir": "packages" diff --git a/package.json b/package.json index 14d13032d..344ff0dac 100644 --- a/package.json +++ b/package.json @@ -20,12 +20,12 @@ "module": "./lib/esm/index.js", "types": "./lib/esm/index.d.ts", "scripts": { - "build": "nx run-many --target=build --projects=near-wallet-selector --configuration=production", + "build": "nx run-many --target=build --projects=@near-wallet-selector/core --configuration=production", "lint": "nx workspace-lint && nx run-many --target=lint --all --parallel", "lint:fix": "nx run-many --target=lint --all --fix", "prepack": "yarn build", "test": "nx run-many --target=test --all", - "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main && nx run near-wallet-selector:build", + "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main && nx run @near-wallet-selector/core:build", "ng": "nx" }, "dependencies": { diff --git a/packages/near-wallet-selector/package.json b/packages/near-wallet-selector/package.json index 5ef837d62..0b74da3d3 100644 --- a/packages/near-wallet-selector/package.json +++ b/packages/near-wallet-selector/package.json @@ -1,4 +1,4 @@ { - "name": "near-wallet-selector", - "version": "0.0.1" + "name": "@near-wallet-selector/core", + "version": "3.0.0-alpha.0" } diff --git a/tsconfig.base.json b/tsconfig.base.json index a85b09ffc..0cb85199e 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -16,7 +16,7 @@ "baseUrl": ".", "strictPropertyInitialization": false, "paths": { - "near-wallet-selector": ["dist/packages/near-wallet-selector"] + "@near-wallet-selector/core": ["dist/packages/near-wallet-selector"] } }, "exclude": ["node_modules", "tmp"] diff --git a/workspace.json b/workspace.json index a55058ea6..33b5485f7 100644 --- a/workspace.json +++ b/workspace.json @@ -3,7 +3,7 @@ "projects": { "angular": "examples/angular", "angular-e2e": "examples/angular-e2e", - "near-wallet-selector": "packages/near-wallet-selector", + "@near-wallet-selector/core": "packages/near-wallet-selector", "react": "examples/react", "react-e2e": "examples/react-e2e" } From a32f35c312227de566533d59651dedd2d410597c Mon Sep 17 00:00:00 2001 From: Lewis Barnes Date: Tue, 29 Mar 2022 15:34:41 +0100 Subject: [PATCH 2/5] Updated imports. --- examples/angular/src/app/app.component.ts | 2 +- .../angular/src/app/components/content/content.component.ts | 2 +- examples/angular/src/app/components/form/form.component.ts | 2 +- examples/angular/src/config.ts | 2 +- examples/react/src/contexts/WalletSelectorContext.tsx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/angular/src/app/app.component.ts b/examples/angular/src/app/app.component.ts index b3c0a89aa..c037d33c5 100644 --- a/examples/angular/src/app/app.component.ts +++ b/examples/angular/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import NearWalletSelector from "near-wallet-selector"; +import NearWalletSelector from "@near-wallet-selector/core"; import getConfig from "../config"; @Component({ diff --git a/examples/angular/src/app/components/content/content.component.ts b/examples/angular/src/app/components/content/content.component.ts index 6b57b9a40..b8571a996 100644 --- a/examples/angular/src/app/components/content/content.component.ts +++ b/examples/angular/src/app/components/content/content.component.ts @@ -2,7 +2,7 @@ import { Component, Input, OnDestroy, OnInit } from "@angular/core"; import NearWalletSelector, { AccountInfo, Subscription, -} from "near-wallet-selector"; +} from "@near-wallet-selector/core"; import { utils } from "near-api-js"; import { Message } from "../../interfaces/message"; import { Sumbitted } from "../form/form.component"; diff --git a/examples/angular/src/app/components/form/form.component.ts b/examples/angular/src/app/components/form/form.component.ts index fa2535de0..0a070c618 100644 --- a/examples/angular/src/app/components/form/form.component.ts +++ b/examples/angular/src/app/components/form/form.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; -import { AccountInfo } from "near-wallet-selector"; +import { AccountInfo } from "@near-wallet-selector/core"; import Big from "big.js"; export type Sumbitted = SubmitEvent & { diff --git a/examples/angular/src/config.ts b/examples/angular/src/config.ts index a21bd0d57..82ff8f42f 100644 --- a/examples/angular/src/config.ts +++ b/examples/angular/src/config.ts @@ -1,4 +1,4 @@ -import { Options } from "near-wallet-selector"; +import { Options } from "near-wallet-selector/core"; const CONTRACT_NAME = "guest-book.testnet"; diff --git a/examples/react/src/contexts/WalletSelectorContext.tsx b/examples/react/src/contexts/WalletSelectorContext.tsx index 3948b0118..6864bbf0c 100644 --- a/examples/react/src/contexts/WalletSelectorContext.tsx +++ b/examples/react/src/contexts/WalletSelectorContext.tsx @@ -1,5 +1,5 @@ import React, { useContext, useEffect, useState } from "react"; -import NearWalletSelector, { AccountInfo } from "near-wallet-selector"; +import NearWalletSelector, { AccountInfo } from "@near-wallet-selector/core"; interface WalletSelectorContextValue { selector: NearWalletSelector; From e6d2fafbb70e9c1199515888a61e1da12d3b0bbe Mon Sep 17 00:00:00 2001 From: Lewis Barnes Date: Tue, 29 Mar 2022 16:25:46 +0100 Subject: [PATCH 3/5] Updated READMEs. --- README.md | 371 +--------------------- package.json | 8 +- packages/near-wallet-selector/README.md | 396 +++++++++++++++++++++++- 3 files changed, 399 insertions(+), 376 deletions(-) diff --git a/README.md b/README.md index 7d9463196..f93961808 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ The NEAR Wallet Selector makes it easy for users to interact with your dApp. Thi - [Math Wallet](https://chrome.google.com/webstore/detail/math-wallet/afbcbjpbpfadlkmhmclhkeeodmamcflc) - Browser extension wallet. - [Ledger](https://www.ledger.com/) - Hardware wallet. - -## Preview +## Preview [React](https://reactjs.org/), [Vue](https://vuejs.org/) and [Angular](https://angular.io/) variations of the [Guest Book](https://github.com/near-examples/guest-book/) dApp can be found in the [`examples`](/examples) directory. You can use these to gain a concrete understanding of how to integrate `near-wallet-selector` into your own dApp. @@ -34,371 +33,7 @@ import NearWalletSelector from "@near-wallet-selector/core"; const selector = await NearWalletSelector.init({ wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], network: "testnet", - contract: { contractId: "guest-book.testnet" }, -}); -``` - -## API Reference - -### `.init(options)` - -**Parameters** - -- `options` (`object`) - - `wallets` (`Array`): List of wallets you want to support in your dApp. - - `network` (`string | object`): Network ID or object matching that of your dApp configuration . Network ID can be either `mainnet`, `testnet` or `betanet`. - - `networkId` (`string`): Custom network ID (e.g. `localnet`). - - `nodeUrl` (`string`): Custom URL for RPC requests. - - `helperUrl` (`string`): Custom URL for creating accounts. - - `explorerUrl` (`string`): Custom URL for - - `contractId` (`string`): Account ID of the Smart Contract used for `.signIn` and `.signAndSendTransaction`. - - `methodNames` (`Array?`): Specify limited access to particular methods on the Smart Contract. - - `ui`: (`object?`) - - `theme` (`string?`): Specify light/dark theme for UI. Defaults to the browser configuration when omitted or set to 'auto'. This can be either `light`, `dark` or `auto`. - - `description` (`string?`): Define a custom description in the UI. - -**Returns** - -- `Promise` - -**Description** - -Initialises the selector using the configured options before rendering the UI. If a user has previously signed in, this method will also initialise the selected wallet, ready to handle signing. - -**Example** - -```ts -await NearWalletSelector.init({ - wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], - network: "testnet", - contract: { contractId: "guest-book.testnet" }, -}); -``` - -### `.show()` - -****Parameters**** - -- N/A - -**Returns** - -- `void` - -**Description** - -Opens the modal for users to sign in to their preferred wallet. You can also use this method to switch wallets. - -**Example** - -```ts -selector.show(); -``` - -### `.hide()` - -**Parameters** - -- N/A - -**Returns** - -- `void` - -**Description** - -Closes the modal. - -**Example** - -```ts -selector.hide(); -``` - -### `.signIn(params)` - -**Parameters** - -- `params` (`object`) - - `walletId` (`string`): ID of the wallet (see example for specific values). - - `accountId` (`string?`): Required for hardware wallets (e.g. Ledger Wallet). This is the account ID related to the public key found at `derivationPath`. - - `derviationPath` (`string?`): Required for hardware wallets (e.g. Ledger Wallet). This is the path to the public key on your device. - -**Returns** - -- `Promise` - -**Description** - -Programmatically sign in to a specific wallet without presenting the UI. Hardware wallets (e.g. Ledger Wallet) require `accountId` and `derivationPath` to validate access key permissions. - -**Example** - -```ts -// NEAR Wallet. -await selector.signIn({ - walletId: "near-wallet", -}); - -// Sender Wallet. -await selector.signIn({ - walletId: "sender-wallet", -}); - -// Math Wallet. -await selector.signIn({ - walletId: "math-wallet", -}); - -// Ledger Wallet -await selector.signIn({ - walletId: "ledger-wallet", - accountId: "account-id.testnet", - derviationPath: "44'/397'/0'/0'/1'", -}); -``` - -### `.signOut()` - -**Parameters** - -- N/A - -**Returns** - -- `Promise` - -**Description** - -Signs out of the selected wallet. - -**Example** - -```ts -await selector.signOut(); -``` - -### `.isSignedIn()` - -**Parameters** - -- N/A - -**Returns** - -- `Promise` - -**Description** - -Determines whether the user is signed in. - -**Example** - -```ts -const signedIn = await selector.isSignedIn(); -console.log(signedIn) // true -``` - -### `.getAccounts()` - -**Parameters** - -- N/A - -**Returns** - -- `Promise>` - - `accountId`: An account id for each account associated with the selected wallet. - -**Description** - -Retrieves account information when the user is signed in. Returns an empty array when the user is signed out. This method can be useful for wallets that support accounts at once such as WalletConnect. In this case, you can use an `accountId` returned as the `signerId` for `signAndSendTransaction`. - -**Example** - -```ts -const accounts = await selector.getAccounts(); -console.log(accounts); // [{ accountId: "test.testnet" }] -``` - -### `.on(event, callback)` - -**Parameters** - -- `event` (`string`): Name of the event. This can be either `signIn` or `signOut`. -- `callback` (`() => void`): Handler to be triggered when the `event` fires. - -**Returns** - -- `object` - - `remove` (`() => void`): Removes the event handler. - -**Description** - -Attach an event handler to important events. - -**Example** - -```ts -const subscription = selector.on("signIn", () => { - console.log("User signed in!"); -}); - -// Unsubscribe. -subscription.remove(); -``` - -### `.off(event, callback)` - -**Parameters** - -- `event` (`string`): Name of the event. This can be either `signIn` or `signOut`. -- `callback` (`() => void`): Original handler passed to `.on(event, callback)`. - -**Returns** - -- `void` - -**Description** - -Removes the event handler attached to the given `event`. - -**Example** - -```ts -const handleSignIn = () => { - console.log("User signed in!"); -} - -selector.on("signIn", handleSignIn); -selector.off("signIn", handleSignIn); -``` - -### `.getContractId()` - -**Parameters** - -- N/A - -**Returns** - -- `string` - -**Description** - -Retrieves account ID of the configured Smart Contract. - -**Example** - -```ts -const contractId = selector.getContractId(); -console.log(contractId); // "guest-book.testnet" -``` - -### `.signAndSendTransaction(params)` - -**Parameters** - -- `params` (`object`) - - `signerId` (`string?`): Account ID used to sign the transaction. Defaults to the first account. - - `actions` (`Array`) - - `type` (`string`): Action type. See below for available values. - - `params` (`object?`): Parameters for the Action (if applicable). - -**Returns** - -- `Promise`: More details on this can be found [here](https://docs.near.org/docs/api/rpc/transactions#send-transaction-await). - -**Description** - -Signs one or more actions before sending to the network. The user must be signed in to call this method as there's at least charges for gas spent. - -Note: Sender Wallet only supports `"FunctionCall"` action types right now. If you wish to use other NEAR Actions in your dApp, it's recommended to remove this wallet in your configuration. - -Below are the 8 supported NEAR Actions: - -```ts -export interface CreateAccountAction { - type: "CreateAccount"; -} - -export interface DeployContractAction { - type: "DeployContract"; - params: { - code: Uint8Array; - }; -} - -export interface FunctionCallAction { - type: "FunctionCall"; - params: { - methodName: string; - args: object; - gas: string; - deposit: string; - }; -} - -export interface TransferAction { - type: "Transfer"; - params: { - deposit: string; - }; -} - -export interface StakeAction { - type: "Stake"; - params: { - stake: string; - publicKey: string; - }; -} - -export interface AddKeyAction { - type: "AddKey"; - params: { - publicKey: string; - accessKey: { - nonce?: number; - permission: - | "FullAccess" - | { - receiverId: string; - allowance?: string; - methodNames?: Array; - }; - }; - }; -} - -export interface DeleteKeyAction { - type: "DeleteKey"; - params: { - publicKey: string; - }; -} - -export interface DeleteAccountAction { - type: "DeleteAccount"; - params: { - beneficiaryId: string; - }; -} -``` - -**Example** - -```ts -await selector.signAndSendTransaction({ - actions: [{ - type: "FunctionCall", - params: { - methodName: "addMessage", - args: { text: "Hello World!" }, - gas: "30000000000000", - deposit: "10000000000000000000000", - } - }] + contractId: "guest-book.testnet", }); ``` @@ -406,7 +41,7 @@ await selector.signAndSendTransaction({ At the time of writing, there is an issue with Sender Wallet where the signed in state is lost when navigating back to a dApp you had previously signed in to - this includes browser refreshes. -## Contributing +## Contributing Contributors may find the [`examples`](./examples) directory useful as it provides a quick and consistent way to manually test new changes and/or bug fixes. Below is a common workflow you can use: diff --git a/package.json b/package.json index 344ff0dac..e8d393620 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { "name": "near-wallet-selector", - "version": "2.0.0", + "version": "3.0.0-alpha.0", "description": "This is a wallet modal that allows users to interact with NEAR dApps with a selection of available wallets.", "keywords": [ "near", "walletselector" ], - "homepage": "https://github.com/near-projects/wallet-selector#readme", + "homepage": "https://github.com/near/wallet-selector#README", "bugs": { - "url": "https://github.com/near-projects/wallet-selector/issues" + "url": "https://github.com/near/wallet-selector/issues" }, "repository": { "type": "git", - "url": "git+https://github.com/near-projects/wallet-selector.git" + "url": "git+https://github.com/near/wallet-selector.git" }, "license": "ISC", "author": "near", diff --git a/packages/near-wallet-selector/README.md b/packages/near-wallet-selector/README.md index 206381cdd..03798e1b3 100644 --- a/packages/near-wallet-selector/README.md +++ b/packages/near-wallet-selector/README.md @@ -1,7 +1,395 @@ -# near-wallet-selector +# @near-wallet-selector/core -This library was generated with [Nx](https://nx.dev). +This is the core package for NEAR Wallet Selector. -## Running unit tests +## Installation and Usage -Run `nx test near-wallet-selector` to execute the unit tests via [Jest](https://jestjs.io). +The easiest way to use this package is to install it from the NPM registry: + +```bash +# Using Yarn +yarn add @near-wallet-selector/core + +# Using NPM. +npm install @near-wallet-selector/core +``` + +Then use it in your dApp: + +```ts +import NearWalletSelector from "@near-wallet-selector/core"; + +const selector = await NearWalletSelector.init({ + wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], + network: "testnet", + contractId: "guest-book.testnet", +}); +``` + +## API Reference + +### `.init(options)` + +**Parameters** + +- `options` (`object`) + - `wallets` (`Array`): List of wallets you want to support in your dApp. + - `network` (`string | object`): Network ID or object matching that of your dApp configuration . Network ID can be either `mainnet`, `testnet` or `betanet`. + - `networkId` (`string`): Custom network ID (e.g. `localnet`). + - `nodeUrl` (`string`): Custom URL for RPC requests. + - `helperUrl` (`string`): Custom URL for creating accounts. + - `explorerUrl` (`string`): Custom URL for + - `contractId` (`string`): Account ID of the Smart Contract used for `.signIn` and `.signAndSendTransaction`. + - `methodNames` (`Array?`): Specify limited access to particular methods on the Smart Contract. + - `ui`: (`object?`) + - `theme` (`string?`): Specify light/dark theme for UI. Defaults to the browser configuration when omitted or set to 'auto'. This can be either `light`, `dark` or `auto`. + - `description` (`string?`): Define a custom description in the UI. + +**Returns** + +- `Promise` + +**Description** + +Initialises the selector using the configured options before rendering the UI. If a user has previously signed in, this method will also initialise the selected wallet, ready to handle signing. + +**Example** + +```ts +await NearWalletSelector.init({ + wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], + network: "testnet", + contract: { contractId: "guest-book.testnet" }, +}); +``` + +### `.show()` + +****Parameters**** + +- N/A + +**Returns** + +- `void` + +**Description** + +Opens the modal for users to sign in to their preferred wallet. You can also use this method to switch wallets. + +**Example** + +```ts +selector.show(); +``` + +### `.hide()` + +**Parameters** + +- N/A + +**Returns** + +- `void` + +**Description** + +Closes the modal. + +**Example** + +```ts +selector.hide(); +``` + +### `.signIn(params)` + +**Parameters** + +- `params` (`object`) + - `walletId` (`string`): ID of the wallet (see example for specific values). + - `accountId` (`string?`): Required for hardware wallets (e.g. Ledger Wallet). This is the account ID related to the public key found at `derivationPath`. + - `derviationPath` (`string?`): Required for hardware wallets (e.g. Ledger Wallet). This is the path to the public key on your device. + +**Returns** + +- `Promise` + +**Description** + +Programmatically sign in to a specific wallet without presenting the UI. Hardware wallets (e.g. Ledger Wallet) require `accountId` and `derivationPath` to validate access key permissions. + +**Example** + +```ts +// NEAR Wallet. +await selector.signIn({ + walletId: "near-wallet", +}); + +// Sender Wallet. +await selector.signIn({ + walletId: "sender-wallet", +}); + +// Math Wallet. +await selector.signIn({ + walletId: "math-wallet", +}); + +// Ledger Wallet +await selector.signIn({ + walletId: "ledger-wallet", + accountId: "account-id.testnet", + derviationPath: "44'/397'/0'/0'/1'", +}); +``` + +### `.signOut()` + +**Parameters** + +- N/A + +**Returns** + +- `Promise` + +**Description** + +Signs out of the selected wallet. + +**Example** + +```ts +await selector.signOut(); +``` + +### `.isSignedIn()` + +**Parameters** + +- N/A + +**Returns** + +- `Promise` + +**Description** + +Determines whether the user is signed in. + +**Example** + +```ts +const signedIn = await selector.isSignedIn(); +console.log(signedIn) // true +``` + +### `.getAccounts()` + +**Parameters** + +- N/A + +**Returns** + +- `Promise>` + - `accountId`: An account id for each account associated with the selected wallet. + +**Description** + +Retrieves account information when the user is signed in. Returns an empty array when the user is signed out. This method can be useful for wallets that support accounts at once such as WalletConnect. In this case, you can use an `accountId` returned as the `signerId` for `signAndSendTransaction`. + +**Example** + +```ts +const accounts = await selector.getAccounts(); +console.log(accounts); // [{ accountId: "test.testnet" }] +``` + +### `.on(event, callback)` + +**Parameters** + +- `event` (`string`): Name of the event. This can be either `signIn` or `signOut`. +- `callback` (`() => void`): Handler to be triggered when the `event` fires. + +**Returns** + +- `object` + - `remove` (`() => void`): Removes the event handler. + +**Description** + +Attach an event handler to important events. + +**Example** + +```ts +const subscription = selector.on("signIn", () => { + console.log("User signed in!"); +}); + +// Unsubscribe. +subscription.remove(); +``` + +### `.off(event, callback)` + +**Parameters** + +- `event` (`string`): Name of the event. This can be either `signIn` or `signOut`. +- `callback` (`() => void`): Original handler passed to `.on(event, callback)`. + +**Returns** + +- `void` + +**Description** + +Removes the event handler attached to the given `event`. + +**Example** + +```ts +const handleSignIn = () => { + console.log("User signed in!"); +} + +selector.on("signIn", handleSignIn); +selector.off("signIn", handleSignIn); +``` + +### `.getContractId()` + +**Parameters** + +- N/A + +**Returns** + +- `string` + +**Description** + +Retrieves account ID of the configured Smart Contract. + +**Example** + +```ts +const contractId = selector.getContractId(); +console.log(contractId); // "guest-book.testnet" +``` + +### `.signAndSendTransaction(params)` + +**Parameters** + +- `params` (`object`) + - `signerId` (`string?`): Account ID used to sign the transaction. Defaults to the first account. + - `actions` (`Array`) + - `type` (`string`): Action type. See below for available values. + - `params` (`object?`): Parameters for the Action (if applicable). + +**Returns** + +- `Promise`: More details on this can be found [here](https://docs.near.org/docs/api/rpc/transactions#send-transaction-await). + +**Description** + +Signs one or more actions before sending to the network. The user must be signed in to call this method as there's at least charges for gas spent. + +Note: Sender Wallet only supports `"FunctionCall"` action types right now. If you wish to use other NEAR Actions in your dApp, it's recommended to remove this wallet in your configuration. + +Below are the 8 supported NEAR Actions: + +```ts +export interface CreateAccountAction { + type: "CreateAccount"; +} + +export interface DeployContractAction { + type: "DeployContract"; + params: { + code: Uint8Array; + }; +} + +export interface FunctionCallAction { + type: "FunctionCall"; + params: { + methodName: string; + args: object; + gas: string; + deposit: string; + }; +} + +export interface TransferAction { + type: "Transfer"; + params: { + deposit: string; + }; +} + +export interface StakeAction { + type: "Stake"; + params: { + stake: string; + publicKey: string; + }; +} + +export interface AddKeyAction { + type: "AddKey"; + params: { + publicKey: string; + accessKey: { + nonce?: number; + permission: + | "FullAccess" + | { + receiverId: string; + allowance?: string; + methodNames?: Array; + }; + }; + }; +} + +export interface DeleteKeyAction { + type: "DeleteKey"; + params: { + publicKey: string; + }; +} + +export interface DeleteAccountAction { + type: "DeleteAccount"; + params: { + beneficiaryId: string; + }; +} +``` + +**Example** + +```ts +await selector.signAndSendTransaction({ + actions: [{ + type: "FunctionCall", + params: { + methodName: "addMessage", + args: { text: "Hello World!" }, + gas: "30000000000000", + deposit: "10000000000000000000000", + } + }] +}); +``` + +## License + +This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). From 48919da5d592044d02935ddcd38de84dfa8799c6 Mon Sep 17 00:00:00 2001 From: Lewis Barnes Date: Tue, 29 Mar 2022 16:31:54 +0100 Subject: [PATCH 4/5] Fixed example. --- packages/near-wallet-selector/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/near-wallet-selector/README.md b/packages/near-wallet-selector/README.md index 03798e1b3..4c55a2999 100644 --- a/packages/near-wallet-selector/README.md +++ b/packages/near-wallet-selector/README.md @@ -59,7 +59,7 @@ Initialises the selector using the configured options before rendering the UI. I await NearWalletSelector.init({ wallets: ["near-wallet", "sender-wallet", "ledger-wallet", "math-wallet"], network: "testnet", - contract: { contractId: "guest-book.testnet" }, + contractId: "guest-book.testnet", }); ``` From b3f0cae0fc7d2c858e38537850638a024bb76b10 Mon Sep 17 00:00:00 2001 From: Lewis Barnes Date: Tue, 29 Mar 2022 18:57:17 +0100 Subject: [PATCH 5/5] Updated commands. --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2b5b8f5a..d3c0a91e1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,8 +18,8 @@ yarn nx r [project][:target][:configuration] [options, ...] In order to run a specific example, make sure you build the UI library beforehand and on each modification by running: ```bash -yarn nx run near-wallet-selector:build #build the library +yarn nx run @near-wallet-selector/core:build # build the library -yarn nx serve react # to run the react example -yarn nx serve angular # to run the angular example +yarn nx serve react # run the react example +yarn nx serve angular # run the angular example ```