Skip to content

Commit

Permalink
Merge pull request #1091 from near/revert-1077-here-wallet-top-level-…
Browse files Browse the repository at this point in the history
…injected

Revert "feat: Update HERE Wallet  and add topLevelInjected"
  • Loading branch information
trechriron authored Apr 3, 2024
2 parents dbe60d9 + 0a275c6 commit 794cf0c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 296 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@angular/platform-browser": "15.2.9",
"@angular/platform-browser-dynamic": "15.2.9",
"@angular/router": "15.2.9",
"@here-wallet/core": "^1.6.6",
"@here-wallet/core": "^1.5.1",
"@jscutlery/semver": "3.1.0",
"@ledgerhq/hw-transport": "6.30.3",
"@ledgerhq/hw-transport-webhid": "6.28.3",
Expand Down
11 changes: 1 addition & 10 deletions packages/core/docs/api/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,7 @@ There are four wallet types:

**Description**

Returns meta information about the wallet such as `name`, `description`, `iconUrl` , `deprecated` and `available` but can include wallet-specific properties such as `downloadUrl`, `useUrlAccountImport` and `topLevelInjected` for injected wallets or `contractId`, `runOnStartup` for instant-link wallets and `walletUrl` for browser wallets.

- `name`: Displayed in modal-ui as wallet name
- `description`: Displayed in modal-ui as wallet description
- `iconUrl`: Displayed in modal-ui as wallet icon
- `deprecated`: Makes the wallet unselectable via modal-ui
- `available`: Makes the wallet unselectable via modal-ui, use if the wallet cannot be selected in the user's environment.
- `downloadUrl`: Link to download injected wallet, available via modal-ui
- `useUrlAccountImport`: If `true`, then this injected wallet supports @account-export api and will be available in the account export modal window
- `topLevelInjected`: If the value `true` is passed for an injected wallet, modal-ui will call the signIn method of this wallet immediately upon initializing setupModal. This will allow wallet applications that open the dApp in the internal browser to immediately log in with the user's wallet.
Returns meta information about the wallet such as `name`, `description`, `iconUrl` , `deprecated` and `available` but can include wallet-specific properties such as `downloadUrl` and `useUrlAccountImport` for injected wallets or `contractId`, `runOnStartup` for instant-link wallets and `walletUrl` for browser wallets.

**Example**

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/lib/wallet/wallet.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ export type BrowserWallet = BaseWallet<

export type InjectedWalletMetadata = BaseWalletMetadata & {
downloadUrl: string;
topLevelInjected?: boolean;
useUrlAccountImport?: boolean;
};

Expand Down
9 changes: 1 addition & 8 deletions packages/here-wallet/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
waitInjectedHereWallet,
type HereProvider,
type HereStrategy,
} from "@here-wallet/core";
import type { HereProvider, HereStrategy } from "@here-wallet/core";
import type { WalletModuleFactory } from "@near-wallet-selector/core";
import type { HereWallet } from "./types";
import { initHereWallet } from "./selector";
Expand All @@ -24,8 +20,6 @@ export function setupHereWallet({
defaultProvider,
}: Options = {}): WalletModuleFactory<HereWallet> {
return async () => {
const isInjected = await waitInjectedHereWallet;

return {
id: "here-wallet",
type: "injected",
Expand All @@ -34,7 +28,6 @@ export function setupHereWallet({
description: "Mobile wallet for NEAR Protocol",
useUrlAccountImport: true,
downloadUrl: "https://herewallet.app",
topLevelInjected: isInjected != null,
iconUrl,
deprecated,
available: true,
Expand Down
15 changes: 8 additions & 7 deletions packages/here-wallet/src/lib/selector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NetworkId } from "@near-wallet-selector/core";
import { HereWallet, waitInjectedHereWallet } from "@here-wallet/core";
import { HereWallet } from "@here-wallet/core";
import type BN from "bn.js";

import type { SelectorInit } from "./types";
Expand Down Expand Up @@ -66,11 +66,8 @@ export const initHereWallet: SelectorInit = async (config) => {
async signIn(data) {
logger.log("HereWallet:signIn");

const isInjected = await waitInjectedHereWallet;
if (!isInjected) {
const contractId = data.contractId !== "" ? data.contractId : undefined;
await here.signIn({ ...data, contractId: contractId });
}
const contractId = data.contractId !== "" ? data.contractId : undefined;
await here.signIn({ ...data, contractId: contractId });

emitter.emit("signedIn", {
contractId: data.contractId,
Expand Down Expand Up @@ -104,8 +101,12 @@ export const initHereWallet: SelectorInit = async (config) => {
logger.log("HereWallet:signAndSendTransaction", data);

const { contract } = store.getState();
if (!here.isSignedIn || !contract) {
throw new Error("Wallet not signed in");
}

return await here.signAndSendTransaction({
receiverId: contract?.contractId,
receiverId: contract.contractId,
...data,
});
},
Expand Down
18 changes: 0 additions & 18 deletions packages/modal-ui-js/src/lib/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,6 @@ export const setupModal = (
): WalletSelectorModal => {
const emitter = new EventEmitter<ModalEvents>();

selector.store.getState().modules.forEach(async (module) => {
if ("topLevelInjected" in module.metadata) {
if (!module.metadata.topLevelInjected) {
return;
}

const wallet = await module.wallet();
if (wallet.type !== "injected") {
return;
}

await wallet.signIn({
contractId: options.contractId,
methodNames: options.methodNames,
});
}
});

modalState = {
container: document.getElementById(MODAL_ELEMENT_ID)!,
selector,
Expand Down
18 changes: 0 additions & 18 deletions packages/modal-ui/src/lib/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ export const setupModal = (

const emitter = new EventEmitter<ModalEvents>();

selector.store.getState().modules.forEach(async (module) => {
if ("topLevelInjected" in module.metadata) {
if (!module.metadata.topLevelInjected) {
return;
}

const wallet = await module.wallet();
if (wallet.type !== "injected") {
return;
}

await wallet.signIn({
contractId: options.contractId,
methodNames: options.methodNames,
});
}
});

const render = (visible = false) => {
root!.render(
<Modal
Expand Down
Loading

0 comments on commit 794cf0c

Please sign in to comment.