Skip to content

Commit

Permalink
Merge pull request #292 from near/task-290/add-near-wallet-callback-u…
Browse files Browse the repository at this point in the history
…rl-main

Add `callbackUrl` Support for Near Wallet (main)
  • Loading branch information
lewis-sqa authored May 23, 2022
2 parents 19af600 + cf97304 commit df1d42a
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 10 deletions.
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": "3.0.2",
"version": "3.1.0",
"description": "This is a wallet modal that allows users to interact with NEAR dApps with a selection of available wallets.",
"keywords": [
"near",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ console.log(contractId); // "guest-book.testnet"
- `actions` (`Array<Action>`)
- `type` (`string`): Action type. See below for available values.
- `params` (`object?`): Parameters for the Action (if applicable).
- `callbackUrl` (`string?`): Applicable to browser wallets (e.g. NEAR Wallet). This the callback url once the transaction is approved.

**Returns**

Expand Down Expand Up @@ -408,6 +409,7 @@ await selector.signAndSendTransaction({
- `actions` (`Array<Action>`)
- `type` (`string`): Action type. See above for available values.
- `params` (`object?`): Parameters for the Action (if applicable).
- `callbackUrl` (`string?`): Applicable to browser wallets (e.g. NEAR Wallet). This the callback url once the transactions are approved.

**Returns**

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@near-wallet-selector/core",
"version": "3.0.2"
"version": "3.1.0"
}
6 changes: 6 additions & 0 deletions packages/core/src/lib/NearWalletSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ interface SignAndSendTransactionParams {
signerId?: string;
receiverId?: string;
actions: Array<Action>;
callbackUrl?: string;
}

interface SignAndSendTransactionsParams {
transactions: Array<Optional<Transaction, "signerId">>;
callbackUrl?: string;
}

export default class NearWalletSelector {
Expand Down Expand Up @@ -119,6 +121,7 @@ export default class NearWalletSelector {
signerId,
receiverId,
actions,
callbackUrl,
}: SignAndSendTransactionParams) {
const wallet = this.controller.getSelectedWallet();
const accounts = await this.getAccounts();
Expand All @@ -139,11 +142,13 @@ export default class NearWalletSelector {
signerId: signerId || accounts[0].accountId,
receiverId: receiverId || this.getContractId(),
actions,
callbackUrl,
});
}

async signAndSendTransactions({
transactions,
callbackUrl,
}: SignAndSendTransactionsParams) {
const wallet = this.controller.getSelectedWallet();
const accounts = await this.getAccounts();
Expand All @@ -168,6 +173,7 @@ export default class NearWalletSelector {
actions,
};
}),
callbackUrl,
});
}
}
16 changes: 16 additions & 0 deletions packages/core/src/lib/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export interface SignAndSendTransactionsParams {
transactions: Array<Transaction>;
}

export interface BrowserWalletSignAndSendTransactionParams
extends SignAndSendTransactionParams {
callbackUrl?: string;
}

export interface BrowserWalletSignAndSendTransactionsParams
extends SignAndSendTransactionsParams {
callbackUrl?: string;
}

export interface AccountInfo {
accountId: string;
}
Expand Down Expand Up @@ -70,6 +80,12 @@ interface BaseWallet<ExecutionOutcome = providers.FinalExecutionOutcome> {

export interface BrowserWallet extends BaseWallet<void> {
type: "browser";
signAndSendTransaction(
params: BrowserWalletSignAndSendTransactionParams
): Promise<void>;
signAndSendTransactions(
params: BrowserWalletSignAndSendTransactionsParams
): Promise<void>;
}

export interface InjectedWallet extends BaseWallet {
Expand Down
2 changes: 1 addition & 1 deletion packages/ledger/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@near-wallet-selector/ledger",
"version": "3.0.2"
"version": "3.1.0"
}
2 changes: 1 addition & 1 deletion packages/math-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@near-wallet-selector/math-wallet",
"version": "3.0.2"
"version": "3.1.0"
}
2 changes: 1 addition & 1 deletion packages/near-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@near-wallet-selector/near-wallet",
"version": "3.0.2"
"version": "3.1.0"
}
17 changes: 14 additions & 3 deletions packages/near-wallet/src/lib/near-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,40 @@ export function setupNearWallet({
return getAccounts();
},

async signAndSendTransaction({ signerId, receiverId, actions }) {
async signAndSendTransaction({
signerId,
receiverId,
actions,
callbackUrl,
}) {
logger.log("NearWallet:signAndSendTransaction", {
signerId,
receiverId,
actions,
callbackUrl,
});

const account = wallet.account();

return account["signAndSendTransaction"]({
receiverId,
actions: transformActions(actions),
walletCallbackUrl: callbackUrl,
}).then(() => {
// Suppress response since transactions with deposits won't actually
// return FinalExecutionOutcome.
});
},

async signAndSendTransactions({ transactions }) {
logger.log("NearWallet:signAndSendTransactions", { transactions });
async signAndSendTransactions({ transactions, callbackUrl }) {
logger.log("NearWallet:signAndSendTransactions", {
transactions,
callbackUrl,
});

return wallet.requestSignTransactions({
transactions: await transformTransactions(transactions),
callbackUrl,
});
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/sender/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@near-wallet-selector/sender",
"version": "3.0.2"
"version": "3.1.0"
}
2 changes: 1 addition & 1 deletion packages/wallet-connect/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@near-wallet-selector/wallet-connect",
"version": "3.0.2"
"version": "3.1.0"
}

0 comments on commit df1d42a

Please sign in to comment.