Skip to content

Commit

Permalink
Merge pull request #581 from near/dev
Browse files Browse the repository at this point in the history
v7.3.0 Release (dev -> main)
  • Loading branch information
kujtimprenkuSQA authored Nov 29, 2022
2 parents b7dc7e2 + 9fb8b16 commit 4425f86
Show file tree
Hide file tree
Showing 72 changed files with 707 additions and 367 deletions.
10 changes: 6 additions & 4 deletions examples/react/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import SignIn from "./SignIn";
import Form from "./Form";
import Messages from "./Messages";

type Submitted = SubmitEvent & {
target: { elements: { [key: string]: HTMLInputElement } };
};

const SUGGESTED_DONATION = "0";
const BOATLOAD_OF_GAS = utils.format.parseNearAmount("0.00000000003")!;

Expand Down Expand Up @@ -182,11 +186,9 @@ const Content: React.FC = () => {
};

const handleSubmit = useCallback(
async (e: SubmitEvent) => {
async (e: Submitted) => {
e.preventDefault();

// TODO: Fix the typing so that target.elements exists..
// @ts-ignore.
const { fieldset, message, donation, multiple } = e.target.elements;

fieldset.disabled = true;
Expand Down Expand Up @@ -245,7 +247,7 @@ const Content: React.FC = () => {
</div>
<Form
account={account}
onSubmit={(e) => handleSubmit(e as unknown as SubmitEvent)}
onSubmit={(e) => handleSubmit(e as unknown as Submitted)}
/>
<Messages messages={messages} />
</Fragment>
Expand Down
5 changes: 4 additions & 1 deletion examples/react/contexts/WalletSelectorContext.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ReactNode } from "react";
import React, { useCallback, useContext, useEffect, useState } from "react";
import { map, distinctUntilChanged } from "rxjs";
import { setupWalletSelector } from "@near-wallet-selector/core";
Expand Down Expand Up @@ -37,7 +38,9 @@ interface WalletSelectorContextValue {
const WalletSelectorContext =
React.createContext<WalletSelectorContextValue | null>(null);

export const WalletSelectorContextProvider: React.FC = ({ children }) => {
export const WalletSelectorContextProvider: React.FC<{
children: ReactNode;
}> = ({ children }) => {
const [selector, setSelector] = useState<WalletSelector | null>(null);
const [modal, setModal] = useState<WalletSelectorModal | null>(null);
const [accounts, setAccounts] = useState<Array<AccountState>>([]);
Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-wallet-selector",
"version": "7.2.1",
"version": "7.3.0",
"description": "NEAR Wallet Selector makes it easy for users to interact with your dApp by providing an abstraction over various wallets within the NEAR ecosystem",
"keywords": [
"near",
Expand Down Expand Up @@ -41,6 +41,7 @@
"build:all": "nx run-many --target=build --all --exclude=react,angular --configuration=production",
"build:core": "nx run-many --target=build --projects=core --configuration=production",
"build:modal-ui": "nx run-many --target=build --projects=modal-ui --configuration=production",
"build:modal-ui-js": "nx run-many --target=build --projects=modal-ui-js --configuration=production",
"build:ledger": "nx run-many --target=build --projects=ledger --configuration=production",
"build:math-wallet": "nx run-many --target=build --projects=math-wallet --configuration=production",
"build:near-wallet": "nx run-many --target=build --projects=near-wallet --configuration=production",
Expand All @@ -63,7 +64,8 @@
"serve:angular": "nx serve angular",
"prepack": "yarn build:core && yarn build:all",
"test": "nx run-many --target=test --all",
"postinstall": "ngcc --properties es2020 browser module main"
"postinstall": "ngcc --properties es2020 browser module main",
"find:unused": "ts-prune -p tsprune.json"
},
"dependencies": {
"@angular/animations": "~14.0.0",
Expand All @@ -74,14 +76,14 @@
"@angular/platform-browser": "~14.0.0",
"@angular/platform-browser-dynamic": "~14.0.0",
"@angular/router": "~14.0.0",
"@jscutlery/semver": "^2.27.1",
"@jscutlery/semver": "^2.27.2",
"@ledgerhq/hw-transport": "6.27.1",
"@ledgerhq/hw-transport-webhid": "6.27.1",
"@metamask/detect-provider": "^2.0.0",
"@meteorwallet/sdk": "^0.6.0",
"@nightlylabs/connect-near": "0.0.13",
"@nightlylabs/connect-near": "0.0.14",
"@walletconnect/qrcode-modal": "2.0.0-alpha.20",
"@walletconnect/sign-client": "2.0.0-rc.4",
"@walletconnect/sign-client": "2.1.1",
"better-sqlite3": "^7.6.2",
"big.js": "^6.1.1",
"bn.js": "^5.2.0",
Expand All @@ -92,7 +94,7 @@
"crypto-browserify": "^3.12.0",
"ethers": "^5.7.2",
"is-mobile": "^3.1.1",
"near-api-js": "^0.44.2",
"near-api-js": "^1.1.0",
"near-seed-phrase": "^0.2.0",
"next": "12.2.3",
"ngx-deploy-npm": "^4.3.1",
Expand All @@ -101,8 +103,8 @@
"react-dom": "18.2.0",
"react-qr-code": "^2.0.8",
"regenerator-runtime": "0.13.10",
"stream-browserify": "^3.0.0",
"rxjs": "^7.5.7",
"stream-browserify": "^3.0.0",
"tslib": "^2.3.0",
"tweetnacl": "^1.0.3",
"zone.js": "~0.11.4"
Expand Down Expand Up @@ -149,7 +151,7 @@
"@types/w3c-web-usb": "^1.0.5",
"@typescript-eslint/eslint-plugin": "5.13.0",
"@typescript-eslint/parser": "5.13.0",
"@walletconnect/types": "^2.0.0-rc.4",
"@walletconnect/types": "^2.1.1",
"babel-jest": "27.2.3",
"cypress": "^9.1.0",
"eslint": "~8.15.0",
Expand All @@ -173,6 +175,7 @@
"ts-jest": "27.1.4",
"ts-node": "~10.8.0",
"typescript": "~4.7.2",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"ts-prune": "^0.10.3"
}
}
4 changes: 2 additions & 2 deletions packages/coin98-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@near-wallet-selector/coin98-wallet",
"version": "7.2.1",
"version": "7.3.0",
"peerDependencies": {
"near-api-js": "^0.44.2"
"near-api-js": "^0.44.2 || ^1.0.0"
}
}
5 changes: 3 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ The easiest way to use this package is to install it from the NPM registry, this

```bash
# Using Yarn
yarn add near-api-js@^0.44.2
yarn add near-api-js

# Using NPM.
npm install near-api-js@^0.44.2
npm install near-api-js
```

```bash
Expand Down Expand Up @@ -44,6 +44,7 @@ const selector = await setupWalletSelector({
- `explorerUrl` (`string`): Custom URL for the NEAR explorer.
- `indexerUrl` (`string`): Custom URL for the Indexer service.
- `debug` (`boolean?`): Enable internal logging for debugging purposes. Defaults to `false`.
- `optimizeWalletOrder` (`boolean?`): Enable automatic wallet order. Reorders last signed in wallet on top, then installed wallets over not installed and deprecated wallets.
- `storage` (`StorageService?`): Async storage implementation. Useful when [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) is unavailable. Defaults to `localStorage`.
- `modules` (`Array<WalletModuleFactory>`): List of wallets to support in your dApp.

Expand Down
1 change: 1 addition & 0 deletions packages/core/docs/api/selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `helperUrl` (`string`): URL for creating accounts.
- `explorerUrl` (`string`): URL for the NEAR explorer.
- `debug` (`boolean`): Whether internal logging is enabled.
- `optimizeWalletOrder` (`boolean`): Whether wallet order optimization is enabled.

**Description**

Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@near-wallet-selector/core",
"version": "7.2.1",
"version": "7.3.0",
"peerDependencies": {
"near-api-js": "^0.44.2"
"near-api-js": "^0.44.2 || ^1.0.0"
}
}
1 change: 1 addition & 0 deletions packages/core/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const PACKAGE_NAME = "near-wallet-selector";
export const RECENTLY_SIGNED_IN_WALLETS = "recentlySignedInWallets";

export const CONTRACT = "contract";
export const PENDING_CONTRACT = "contract:pending";
Expand Down
53 changes: 53 additions & 0 deletions packages/core/src/lib/locale/zh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"modal": {
"wallet": {
"connectYourWallet": "连接你的钱包",
"whatIsAWallet": "什么是钱包?",
"secureAndManage": "保护和管理你的数字资产",
"safelyStore": "安全存储和转移你的加密货币和NFT",
"logInToAny": "登录任何 NEAR 应用",
"noNeedToCreate": "不需要创建新账户或密码。连接你的钱包,即可开始使用!",
"getAWallet": "获取新账户",
"useAWallet": "使用钱包来保护和管理你的 NEAR 资产,无需用户名和密码即可登录任何 NEAR 应用",
"connectionFailed": "连接失败",
"connectionSuccessful": "连接成功",
"connected": "已连接",
"connectingTo": "正在连接"
},
"ledger": {
"connectWithLedger": "连接 Ledger",
"makeSureYourLedger": "确保你的 Ledger 已经安全连接,并且 NEAR 应用已经在你设备上打开",
"continue": "继续",
"specifyHDPath": "指定 HD 路径",
"enterYourPreferredHDPath": "输入你偏好的 HD 路径,然后为任意活跃账户扫码",
"scan": "扫码",
"retry": "重试",
"ledgerIsNotAvailable": "Ledger 不可用",
"accessDeniedToUseLedgerDevice": "访问 Ledger 设备被拒绝",
"noAccountsFound": "没有找到账户",
"selectYourAccounts": "选择你的账户",
"connecting1Account": "正在连接1个账户",
"cantFindAnyAccount": "没有找到任何与这个 Ledger 相关联的账户。请创建新账户于",
"orConnectAnAnotherLedger.": "或连接另一个 Ledger",
"connecting": "正在连接",
"ofAccounts": "个账户",
"failedToAutomatically": "无法自动找到账户ID,请主动提供:",
"overviewTheListOfAuthorized": "请查看已授权的账户列表,点击以下按钮完成登录",
"finish": "完成"
},
"install": {
"youllNeedToInstall": "你将需要安装",
"toContinueAfterInstalling": "以继续。安装完",
"refreshThePage": "请刷新页面",
"open": "打开"
},
"qr": {
"copiedToClipboard": "复制到了剪贴板",
"failedToCopy": "复制到剪贴板失败",
"scanWithYourMobile": "用你的移动设备扫码",
"copyToClipboard": " 复制到剪贴板",
"preferTheOfficial": "希望使用官方对话框于",
"open": "打开"
}
}
}
1 change: 1 addition & 0 deletions packages/core/src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const resolveOptions = (params: WalletSelectorParams) => {
const options: Options = {
network: resolveNetwork(params.network),
debug: params.debug || false,
optimizeWalletOrder: params.optimizeWalletOrder === false ? false : true,
};

return {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/options.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface Network {
export interface Options {
network: Network;
debug: boolean;
optimizeWalletOrder: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EventEmitter } from "../event-emitter/event-emitter.service";
import type { WalletSelectorEvents } from "../../wallet-selector.types";
import { Logger, logger } from "../logger/logger.service";
import {
RECENTLY_SIGNED_IN_WALLETS,
PACKAGE_NAME,
PENDING_CONTRACT,
PENDING_SELECTED_WALLET_ID,
Expand Down Expand Up @@ -95,32 +96,65 @@ export class WalletModules {
});
}

const recentlySignedInWalletsFromPending =
await this.setWalletAsRecentlySignedIn(pendingSelectedWalletId);

return {
accounts,
contract: pendingContract,
selectedWalletId: pendingSelectedWalletId,
recentlySignedInWallets: recentlySignedInWalletsFromPending,
};
}
}

const { contract, selectedWalletId } = this.store.getState();
const accounts = await this.validateWallet(selectedWalletId);

const recentlySignedInWallets = await jsonStorage.getItem<Array<string>>(
RECENTLY_SIGNED_IN_WALLETS
);

if (!accounts.length) {
return {
accounts: [],
contract: null,
selectedWalletId: null,
recentlySignedInWallets: recentlySignedInWallets || [],
};
}

return {
accounts,
contract,
selectedWalletId,
recentlySignedInWallets: recentlySignedInWallets || [],
};
}

private async setWalletAsRecentlySignedIn(walletId: string) {
const jsonStorage = new JsonStorage(this.storage, PACKAGE_NAME);

let recentlySignedInWallets = await jsonStorage.getItem<Array<string>>(
RECENTLY_SIGNED_IN_WALLETS
);

if (!recentlySignedInWallets) {
recentlySignedInWallets = [];
}

if (!recentlySignedInWallets.includes(walletId)) {
recentlySignedInWallets.unshift(walletId);
recentlySignedInWallets = recentlySignedInWallets.slice(0, 5);
await jsonStorage.setItem(
RECENTLY_SIGNED_IN_WALLETS,
recentlySignedInWallets
);
}

return recentlySignedInWallets;
}

private async signOutWallet(walletId: string) {
const wallet = (await this.getWallet(walletId))!;

Expand Down Expand Up @@ -157,26 +191,30 @@ export class WalletModules {
await this.signOutWallet(selectedWalletId);
}

const recentlySignedInWallets = await this.setWalletAsRecentlySignedIn(
walletId
);

this.store.dispatch({
type: "WALLET_CONNECTED",
payload: { walletId, contract, accounts, recentlySignedInWallets },
});

this.emitter.emit("signedIn", {
walletId,
contractId,
methodNames,
accounts,
});

this.store.dispatch({
type: "WALLET_CONNECTED",
payload: { walletId, contract, accounts },
});
}

private onWalletSignedOut(walletId: string) {
this.emitter.emit("signedOut", { walletId });

this.store.dispatch({
type: "WALLET_DISCONNECTED",
payload: { walletId },
});

this.emitter.emit("signedOut", { walletId });
}

private setupWalletEmitter(module: WalletModule) {
Expand Down Expand Up @@ -335,7 +373,7 @@ export class WalletModules {

this.modules = modules;

const { accounts, contract, selectedWalletId } =
const { accounts, contract, selectedWalletId, recentlySignedInWallets } =
await this.resolveStorageState();

this.store.dispatch({
Expand All @@ -345,6 +383,7 @@ export class WalletModules {
accounts,
contract,
selectedWalletId,
recentlySignedInWallets,
},
});
}
Expand Down
Loading

0 comments on commit 4425f86

Please sign in to comment.