Skip to content

Commit

Permalink
Merge pull request #706 from near/dev
Browse files Browse the repository at this point in the history
v7.8.1 Release (dev -> main)
  • Loading branch information
kujtimprenkuSQA authored Feb 20, 2023
2 parents 7b8c36b + 336cde6 commit deed838
Show file tree
Hide file tree
Showing 34 changed files with 129 additions and 61 deletions.
31 changes: 31 additions & 0 deletions examples/angular/src/app/components/content/content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { distinctUntilChanged, map } from "rxjs";
import { WalletSelectorModal } from "@near-wallet-selector/modal-ui";
import { CONTRACT_ID } from "../../../constants";
import { WalletSelector } from "@near-wallet-selector/core";
import type { GetAccountBalanceProps } from "../../interfaces/account-balance";
import BN from "bn.js";

const SUGGESTED_DONATION = "0";
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand All @@ -34,6 +36,7 @@ export class ContentComponent implements OnInit, OnDestroy {
account: Account | null;
messages: Array<Message>;
subscription?: Subscription;
getAccountBalanceProps: GetAccountBalanceProps;

async ngOnInit() {
const [messages, account] = await Promise.all([
Expand All @@ -47,6 +50,20 @@ export class ContentComponent implements OnInit, OnDestroy {
this.subscribeToEvents();
}

async getAccountBalance({ provider, accountId }: GetAccountBalanceProps) {
try {
const { amount } = await provider.query<AccountView>({
request_type: "view_account",
finality: "final",
account_id: accountId,
});
const bn = new BN(amount);
return { hasBalance: !bn.isZero() };
} catch {
return { hasBalance: false };
}
}

async getAccount() {
if (!this.accountId) {
return null;
Expand All @@ -55,6 +72,20 @@ export class ContentComponent implements OnInit, OnDestroy {
const { network } = this.selector.options;
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });

const { hasBalance } = await this.getAccountBalance({
provider,
accountId: this.accountId,
});

if (!hasBalance) {
window.alert(
`Account ID: ${this.accountId} has not been founded. Please send some NEAR into this account.`
);
const wallet = await this.selector.wallet();
await wallet.signOut();
return null;
}

return provider
.query<AccountView>({
request_type: "view_account",
Expand Down
6 changes: 6 additions & 0 deletions examples/angular/src/app/interfaces/account-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { providers } from "near-api-js";

export interface GetAccountBalanceProps {
provider: providers.Provider;
accountId: string;
}
37 changes: 37 additions & 0 deletions examples/react/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
CodeResult,
} from "near-api-js/lib/providers/provider";
import type { Transaction } from "@near-wallet-selector/core";
import BN from "bn.js";

import type { Account, Message } from "../interfaces";
import { useWalletSelector } from "../contexts/WalletSelectorContext";
Expand All @@ -20,6 +21,28 @@ type Submitted = SubmitEvent & {
const SUGGESTED_DONATION = "0";
const BOATLOAD_OF_GAS = utils.format.parseNearAmount("0.00000000003")!;

interface GetAccountBalanceProps {
provider: providers.Provider;
accountId: string;
}

const getAccountBalance = async ({
provider,
accountId,
}: GetAccountBalanceProps) => {
try {
const { amount } = await provider.query<AccountView>({
request_type: "view_account",
finality: "final",
account_id: accountId,
});
const bn = new BN(amount);
return { hasBalance: !bn.isZero() };
} catch {
return { hasBalance: false };
}
};

const Content: React.FC = () => {
const { selector, modal, accounts, accountId } = useWalletSelector();
const [account, setAccount] = useState<Account | null>(null);
Expand All @@ -34,6 +57,20 @@ const Content: React.FC = () => {
const { network } = selector.options;
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });

const { hasBalance } = await getAccountBalance({
provider,
accountId,
});

if (!hasBalance) {
window.alert(
`Account ID: ${accountId} has not been founded. Please send some NEAR into this account.`
);
const wallet = await selector.wallet();
await wallet.signOut();
return null;
}

return provider
.query<AccountView>({
request_type: "view_account",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-wallet-selector",
"version": "7.8.0",
"version": "7.8.1",
"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
2 changes: 1 addition & 1 deletion packages/account-export/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/account-export",
"version": "7.8.0",
"version": "7.8.1",
"description": "This is the Export Selector UI package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/coin98-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/coin98-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "Coin 98 wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/core",
"version": "7.8.0",
"version": "7.8.1",
"description": "This is the core package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/default-wallets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/default-wallets",
"version": "7.8.0",
"version": "7.8.1",
"description": "Default wallets package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/finer-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/finer-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "FiNER Wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/here-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/here-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "Here wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/ledger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/ledger",
"version": "7.8.0",
"version": "7.8.1",
"description": "Ledger package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/math-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/math-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "Math wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/meteor-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/meteor-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "Meteor wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
11 changes: 5 additions & 6 deletions packages/meteor-wallet/src/lib/meteor-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ const createMeteorWalletInjected: WalletBehaviourFactory<
return [];
}

const publicKey = await account.connection.signer.getPublicKey(
account.accountId,
options.network.networkId
);
return [
{
accountId,
publicKey: (
await account.connection.signer.getPublicKey(
account.accountId,
options.network.networkId
)
).toString(),
publicKey: publicKey ? publicKey.toString() : "",
},
];
};
Expand Down
2 changes: 1 addition & 1 deletion packages/modal-ui-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/modal-ui-js",
"version": "7.8.0",
"version": "7.8.1",
"description": "Modal UI package for NEAR wallet Selector",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/modal-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/modal-ui",
"version": "7.8.0",
"version": "7.8.1",
"description": "Modal UI package for NEAR wallet Selector",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/modal-ui/src/lib/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const Modal: React.FC<ModalProps> = ({
}
hide();
},
[hide]
[hide, emitter]
);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/modal-ui/src/lib/components/WalletConnected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const WalletConnected: React.FC<WalletConnectedProps> = ({
return (
<Fragment>
<div className="nws-modal-header">
<h3 className="middleTitle"></h3>
<h3 className="middleTitle">{``}</h3>
<CloseButton onClick={onCloseModal} />
</div>
<div className="connecting-wrapper">
Expand Down
2 changes: 1 addition & 1 deletion packages/my-near-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/my-near-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "My Near Wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
30 changes: 11 additions & 19 deletions packages/my-near-wallet/src/lib/my-near-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,17 @@ const MyNearWallet: WalletBehaviourFactory<
if (!accountId || !account) {
return [];
}
try {
const publicKey = await account.connection.signer.getPublicKey(
account.accountId,
options.network.networkId
);
return [
{
accountId,
publicKey: publicKey.toString(),
},
];
} catch (e) {
return [
{
accountId,
publicKey: undefined,
},
];
}

const publicKey = await account.connection.signer.getPublicKey(
account.accountId,
options.network.networkId
);
return [
{
accountId,
publicKey: publicKey ? publicKey.toString() : "",
},
];
};

const transformTransactions = async (
Expand Down
2 changes: 1 addition & 1 deletion packages/narwallets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/narwallets",
"version": "7.8.0",
"version": "7.8.1",
"description": "This is the Narwallets package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/near-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/near-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "Near Wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/nearfi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/nearfi",
"version": "7.8.0",
"version": "7.8.1",
"description": "Nearfi package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/neth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/neth",
"version": "7.8.0",
"version": "7.8.1",
"description": "Control NEAR accounts with ETH accounts",
"author": "mattlockyer",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/nightly-connect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/nightly-connect",
"version": "7.8.0",
"version": "7.8.1",
"description": "Nightly connect package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/nightly/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/nightly",
"version": "7.8.0",
"version": "7.8.1",
"description": "Nightly wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/opto-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/opto-wallet",
"version": "7.8.0",
"version": "7.8.1",
"description": "Opto wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/sender/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/sender",
"version": "7.8.0",
"version": "7.8.1",
"description": "Sender wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
19 changes: 11 additions & 8 deletions packages/sender/src/lib/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,20 @@ const Sender: WalletBehaviourFactory<InjectedWallet> = async ({

const account = _state.wallet.account();

// When wallet is locked signer is empty an object {}.
if (!account!.connection.signer.getPublicKey) {
return [{ accountId, publicKey: undefined }];
}

const publicKey = await account!.connection.signer.getPublicKey(
account!.accountId,
options.network.networkId
);

return [
{
accountId,
publicKey: account
? (
await account.connection.signer.getPublicKey(
account.accountId,
options.network.networkId
)
).toString()
: undefined,
publicKey: publicKey ? publicKey.toString() : undefined,
},
];
};
Expand Down
Loading

0 comments on commit deed838

Please sign in to comment.