Skip to content

Commit

Permalink
Merge pull request #326 from near/dev
Browse files Browse the repository at this point in the history
v4.1.0 Release (dev -> main)
  • Loading branch information
lewis-sqa authored Jun 16, 2022
2 parents d09f69e + 388bfd1 commit c69bac2
Show file tree
Hide file tree
Showing 56 changed files with 1,224 additions and 409 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NEAR Wallet Selector makes it easy for users to interact with your dApp by provi
- [My NEAR Wallet](https://www.npmjs.com/package/@near-wallet-selector/my-near-wallet) - Browser wallet.
- [Sender](https://www.npmjs.com/package/@near-wallet-selector/sender) - Injected wallet.
- [Math Wallet](https://www.npmjs.com/package/@near-wallet-selector/math-wallet) - Injected wallet.
- [Nightly](https://www.npmjs.com/package/@near-wallet-selector/nightly) - Injected wallet.
- [Ledger](https://www.npmjs.com/package/@near-wallet-selector/ledger) - Hardware wallet.
- [WalletConnect](https://www.npmjs.com/package/@near-wallet-selector/wallet-connect) - Bridge wallet.

Expand Down Expand Up @@ -36,6 +37,7 @@ yarn add \
@near-wallet-selector/my-near-wallet \
@near-wallet-selector/sender \
@near-wallet-selector/math-wallet \
@near-wallet-selector/nightly \
@near-wallet-selector/ledger \
@near-wallet-selector/wallet-connect

Expand All @@ -45,6 +47,7 @@ npm install \
@near-wallet-selector/my-near-wallet \
@near-wallet-selector/sender \
@near-wallet-selector/math-wallet \
@near-wallet-selector/nightly \
@near-wallet-selector/ledger \
@near-wallet-selector/wallet-connect
```
Expand All @@ -68,6 +71,7 @@ import { setupNearWallet } from "@near-wallet-selector/near-wallet";
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet";
import { setupSender } from "@near-wallet-selector/sender";
import { setupMathWallet } from "@near-wallet-selector/math-wallet";
import { setupNightly } from "@near-wallet-selector/nightly";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect";

Expand All @@ -77,8 +81,9 @@ const selector = await setupWalletSelector({
setupNearWallet(),
setupMyNearWallet(),
setupSender(),
setupLedger(),
setupMathWallet(),
setupNightly(),
setupLedger(),
setupWalletConnect({
projectId: "c4f79cc...",
metadata: {
Expand Down
5 changes: 5 additions & 0 deletions examples/angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"input": "packages/sender/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/nightly/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/ledger/assets/",
Expand Down
8 changes: 5 additions & 3 deletions examples/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type { WalletSelector, AccountState } from "@near-wallet-selector/core";
import { setupNearWallet } from "@near-wallet-selector/near-wallet";
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet";
import { setupSender } from "@near-wallet-selector/sender";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupMathWallet } from "@near-wallet-selector/math-wallet";
import { setupNightly } from "@near-wallet-selector/nightly";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect";
import { setupModal } from "@near-wallet-selector/modal-ui";
import type { WalletSelectorModal } from "@near-wallet-selector/modal-ui";
Expand Down Expand Up @@ -68,10 +69,11 @@ export class AppComponent implements OnInit {
setupNearWallet(),
setupMyNearWallet(),
setupSender(),
setupLedger(),
setupMathWallet(),
setupNightly(),
setupLedger(),
setupWalletConnect({
projectId: "d43d7d0e46eea5ee28e1f75e1131f984",
projectId: "c4f79cc...",
metadata: {
name: "NEAR Wallet Selector",
description: "Example dApp used by NEAR Wallet Selector",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<ng-container *ngIf="account">
<div>
<button (click)="signOut()">Log out</button>
<button (click)="switchProvider()">Switch Provider</button>
<button (click)="onSendMultipleTransactions()">
Send Multiple Transactions
</button>
<button (click)="switchWallet()">Switch Wallet</button>
<button *ngIf="accounts.length > 1" (click)="switchAccount()">
Switch Account
</button>
Expand Down
117 changes: 56 additions & 61 deletions examples/angular/src/app/components/content/content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { Account } from "../../interfaces/account";
import { distinctUntilChanged, map, Subscription } from "rxjs";
import type { WalletSelectorModal } from "@near-wallet-selector/modal-ui";
import { CONTRACT_ID } from "../../../constants";
import { Transaction } from "@near-wallet-selector/core";

const SUGGESTED_DONATION = "0";
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -77,7 +78,7 @@ export class ContentComponent implements OnInit, OnDestroy {
});
}

switchProvider() {
switchWallet() {
this.modal.show();
}

Expand Down Expand Up @@ -114,48 +115,6 @@ export class ContentComponent implements OnInit, OnDestroy {
});
}

async onSendMultipleTransactions() {
const { contract } = this.selector.store.getState();
const wallet = await this.selector.wallet();

wallet.signAndSendTransactions({
transactions: [
{
// Deploy your own version of https://github.com/near-examples/rust-counter using Gitpod to get a valid receiverId.
receiverId: "dev-1648806797290-14624341764914",
actions: [
{
type: "FunctionCall",
params: {
methodName: "increment",
args: {},
gas: BOATLOAD_OF_GAS,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
deposit: utils.format.parseNearAmount("0")!,
},
},
],
},
{
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
receiverId: contract!.contractId,
actions: [
{
type: "FunctionCall",
params: {
methodName: "addMessage",
args: { text: "Hello World!" },
gas: BOATLOAD_OF_GAS,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
deposit: utils.format.parseNearAmount("0")!,
},
},
],
},
],
});
}

syncAccountState(
currentAccountId: string | null,
newAccounts: Array<AccountState>
Expand Down Expand Up @@ -201,39 +160,75 @@ export class ContentComponent implements OnInit, OnDestroy {
});
}

async onSubmit(e: Submitted) {
const { fieldset, message, donation } = e.target.elements;
async addMessages(message: string, donation: string, multiple: boolean) {
const { contract } = this.selector.store.getState();
const wallet = await this.selector.wallet();

fieldset.disabled = true;
if (!multiple) {
return wallet
.signAndSendTransaction({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
signerId: this.accountId!,
actions: [
{
type: "FunctionCall",
params: {
methodName: "addMessage",
args: { text: message },
gas: BOATLOAD_OF_GAS,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
deposit: utils.format.parseNearAmount(donation)!,
},
},
],
})
.catch((err) => {
alert("Failed to add message");
console.log("Failed to add message");

// TODO: optimistically update page with new message,
// update blockchain data in background
// add uuid to each message, so we know which one is already known
throw err;
});
}

const wallet = await this.selector.wallet();
const transactions: Array<Transaction> = [];

wallet
.signAndSendTransaction({
for (let i = 0; i < 2; i += 1) {
transactions.push({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
signerId: this.accountId!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
receiverId: contract!.contractId,
actions: [
{
type: "FunctionCall",
params: {
methodName: "addMessage",
args: { text: message.value },
gas: BOATLOAD_OF_GAS as string,
args: {
text: `${message} (${i + 1}/2)`,
},
gas: BOATLOAD_OF_GAS,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
deposit: utils.format.parseNearAmount(donation.value || "0")!,
deposit: utils.format.parseNearAmount(donation)!,
},
},
],
})
.catch((err) => {
alert("Failed to add message");
console.log("Failed to add message");
throw err;
})
});
}

return wallet.signAndSendTransactions({ transactions }).catch((err) => {
alert("Failed to add messages");
console.log("Failed to add messages");

throw err;
});
}

async onSubmit(e: Submitted) {
const { fieldset, message, donation, multiple } = e.target.elements;

fieldset.disabled = true;

this.addMessages(message.value, donation.value || "0", multiple.checked)
.then(() => {
return this.getMessages()
.then((nextMessages) => {
Expand Down
4 changes: 4 additions & 0 deletions examples/angular/src/app/components/form/form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
/>
<span title="NEAR Tokens"></span>
</p>
<p>
<label htmlFor="multiple">Multiple Transactions:</label>
<input id="multiple" type="checkbox" />
</p>
<button type="submit">Sign</button>
</fieldset>
</form>
4 changes: 4 additions & 0 deletions examples/angular/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ input[type="number"] {
}
}

input[type="checkbox"] {
margin: 0 1em;
}

button, input {
background: transparent;
color: inherit;
Expand Down
5 changes: 5 additions & 0 deletions examples/react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"input": "packages/sender/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/nightly/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/ledger/assets/",
Expand Down
Loading

0 comments on commit c69bac2

Please sign in to comment.