diff --git a/package.json b/package.json index 1a2542a51..75b164c3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "near-wallet-selector", - "version": "8.9.6", + "version": "8.9.7", "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", @@ -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.5.1", + "@here-wallet/core": "^1.6.6", "@jscutlery/semver": "3.1.0", "@ledgerhq/hw-transport": "6.30.3", "@ledgerhq/hw-transport-webhid": "6.28.3", diff --git a/packages/account-export/package.json b/packages/account-export/package.json index 0db32f9e0..f802585a4 100644 --- a/packages/account-export/package.json +++ b/packages/account-export/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/account-export", - "version": "8.9.6", + "version": "8.9.7", "description": "This is the Export Selector UI package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/bitget-wallet/package.json b/packages/bitget-wallet/package.json index 204bb45c7..612167782 100644 --- a/packages/bitget-wallet/package.json +++ b/packages/bitget-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/bitget-wallet", - "version": "8.9.6", + "version": "8.9.7", "description": "Bitget wallet package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/coin98-wallet/package.json b/packages/coin98-wallet/package.json index ef9dafcd7..3f1153ba1 100644 --- a/packages/coin98-wallet/package.json +++ b/packages/coin98-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/coin98-wallet", - "version": "8.9.6", + "version": "8.9.7", "description": "Coin 98 wallet package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/core/docs/api/wallet.md b/packages/core/docs/api/wallet.md index c7eb30170..c2295e0bc 100644 --- a/packages/core/docs/api/wallet.md +++ b/packages/core/docs/api/wallet.md @@ -63,7 +63,16 @@ 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` and `useUrlAccountImport` for injected wallets or `contractId`, `runOnStartup` for instant-link wallets and `walletUrl` for browser wallets. +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. **Example** diff --git a/packages/core/package.json b/packages/core/package.json index f8951fef9..e5ee2406a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/core", - "version": "8.9.6", + "version": "8.9.7", "description": "This is the core package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/core/src/lib/wallet/wallet.types.ts b/packages/core/src/lib/wallet/wallet.types.ts index 586e4c1bc..9ef2c7cae 100644 --- a/packages/core/src/lib/wallet/wallet.types.ts +++ b/packages/core/src/lib/wallet/wallet.types.ts @@ -258,6 +258,7 @@ export type BrowserWallet = BaseWallet< export type InjectedWalletMetadata = BaseWalletMetadata & { downloadUrl: string; + topLevelInjected?: boolean; useUrlAccountImport?: boolean; }; diff --git a/packages/here-wallet/package.json b/packages/here-wallet/package.json index 1a277c091..985e8ac51 100644 --- a/packages/here-wallet/package.json +++ b/packages/here-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/here-wallet", - "version": "8.9.6", + "version": "8.9.7", "description": "Here wallet package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/here-wallet/src/lib/index.ts b/packages/here-wallet/src/lib/index.ts index acfcf5823..3224b4da6 100644 --- a/packages/here-wallet/src/lib/index.ts +++ b/packages/here-wallet/src/lib/index.ts @@ -1,4 +1,8 @@ -import type { HereProvider, HereStrategy } from "@here-wallet/core"; +import { + waitInjectedHereWallet, + type HereProvider, + type HereStrategy, +} from "@here-wallet/core"; import type { WalletModuleFactory } from "@near-wallet-selector/core"; import type { HereWallet } from "./types"; import { initHereWallet } from "./selector"; @@ -20,6 +24,8 @@ export function setupHereWallet({ defaultProvider, }: Options = {}): WalletModuleFactory { return async () => { + const isInjected = await waitInjectedHereWallet; + return { id: "here-wallet", type: "injected", @@ -28,6 +34,7 @@ export function setupHereWallet({ description: "Mobile wallet for NEAR Protocol", useUrlAccountImport: true, downloadUrl: "https://herewallet.app", + topLevelInjected: isInjected != null, iconUrl, deprecated, available: true, diff --git a/packages/here-wallet/src/lib/selector.ts b/packages/here-wallet/src/lib/selector.ts index 6d810183a..b14eebac9 100644 --- a/packages/here-wallet/src/lib/selector.ts +++ b/packages/here-wallet/src/lib/selector.ts @@ -1,5 +1,5 @@ import type { NetworkId } from "@near-wallet-selector/core"; -import { HereWallet } from "@here-wallet/core"; +import { HereWallet, waitInjectedHereWallet } from "@here-wallet/core"; import type BN from "bn.js"; import type { SelectorInit } from "./types"; @@ -66,8 +66,11 @@ export const initHereWallet: SelectorInit = async (config) => { async signIn(data) { logger.log("HereWallet:signIn"); - const contractId = data.contractId !== "" ? data.contractId : undefined; - await here.signIn({ ...data, contractId: contractId }); + const isInjected = await waitInjectedHereWallet; + if (!isInjected) { + const contractId = data.contractId !== "" ? data.contractId : undefined; + await here.signIn({ ...data, contractId: contractId }); + } emitter.emit("signedIn", { contractId: data.contractId, @@ -101,12 +104,8 @@ 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, }); }, diff --git a/packages/ledger/package.json b/packages/ledger/package.json index 358c39342..85cf7bc80 100644 --- a/packages/ledger/package.json +++ b/packages/ledger/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/ledger", - "version": "8.9.6", + "version": "8.9.7", "description": "Ledger package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/math-wallet/package.json b/packages/math-wallet/package.json index 47ff7f86e..7019bdce8 100644 --- a/packages/math-wallet/package.json +++ b/packages/math-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/math-wallet", - "version": "8.9.6", + "version": "8.9.7", "description": "Math wallet package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/meteor-wallet/package.json b/packages/meteor-wallet/package.json index 4463dd36b..686b12006 100644 --- a/packages/meteor-wallet/package.json +++ b/packages/meteor-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/meteor-wallet", - "version": "8.9.6", + "version": "8.9.7", "description": "Meteor wallet package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/mintbase-wallet/package.json b/packages/mintbase-wallet/package.json index 636f23d60..c099ace6e 100644 --- a/packages/mintbase-wallet/package.json +++ b/packages/mintbase-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/mintbase-wallet", - "version": "8.9.6", + "version": "8.9.7", "description": "Mintbase wallet package for NEAR Wallet Selector.", "keywords": [ "near", diff --git a/packages/modal-ui-js/package.json b/packages/modal-ui-js/package.json index 61539d262..7020ee8c5 100644 --- a/packages/modal-ui-js/package.json +++ b/packages/modal-ui-js/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/modal-ui-js", - "version": "8.9.6", + "version": "8.9.7", "description": "Modal UI package for NEAR wallet Selector", "keywords": [ "near", diff --git a/packages/modal-ui-js/src/lib/modal.ts b/packages/modal-ui-js/src/lib/modal.ts index 668a5e3fa..236aba608 100644 --- a/packages/modal-ui-js/src/lib/modal.ts +++ b/packages/modal-ui-js/src/lib/modal.ts @@ -54,6 +54,24 @@ export const setupModal = ( ): WalletSelectorModal => { const emitter = new EventEmitter(); + 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, diff --git a/packages/modal-ui/package.json b/packages/modal-ui/package.json index de30ff6c4..6345ea4bd 100644 --- a/packages/modal-ui/package.json +++ b/packages/modal-ui/package.json @@ -1,6 +1,6 @@ { "name": "@near-wallet-selector/modal-ui", - "version": "8.9.6", + "version": "8.9.7", "description": "Modal UI package for NEAR wallet Selector", "keywords": [ "near", diff --git a/packages/modal-ui/src/lib/modal.tsx b/packages/modal-ui/src/lib/modal.tsx index 8e8550581..c431ac29b 100644 --- a/packages/modal-ui/src/lib/modal.tsx +++ b/packages/modal-ui/src/lib/modal.tsx @@ -34,6 +34,24 @@ export const setupModal = ( const emitter = new EventEmitter(); + 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( = 1.5.0 < 2" + toidentifier "1.0.0" + http-errors@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3" @@ -15416,6 +15591,11 @@ lru-cache@^9.1.1: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.0.3.tgz#b40014d7d2d16d94130b87297a04a1f24874ae7c" integrity sha512-B7gr+F6MkqB3uzINHXNctGieGsRTMwIBgxkp0yq/5BwcuDzD4A8wQpHQW6vDAm1uKSLQghmRdD9sKqf2vJ1cEg== +lru_map@0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.4.1.tgz#f7b4046283c79fb7370c36f8fca6aee4324b0a98" + integrity sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg== + ltgt@^2.1.2: version "2.2.1" resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5" @@ -16066,6 +16246,11 @@ multiformats@^9.4.2: resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.7.0.tgz#845799e8df70fbb6b15922500e45cb87cf12f7e5" integrity sha512-uv/tcgwk0yN4DStopnBN4GTgvaAlYdy6KnZpuzEPFOYQd71DYFJjs0MN1ERElAflrZaYyGBWXyGxL5GgrxIx0Q== +mustache@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.0.0.tgz#7f02465dbb5b435859d154831c032acdfbbefb31" + integrity sha512-FJgjyX/IVkbXBXYUwH+OYwQKqWpFPLaLVESd70yHjSDunwzV2hZOoTBvPf4KLoxesUzzyfTH6F784Uqd7Wm5yA== + mustache@^4.0.0: version "4.2.0" resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64" @@ -16187,6 +16372,32 @@ near-api-js@^2.1.3: node-fetch "^2.6.1" tweetnacl "^1.0.1" +near-api-js@^3.0.1: + version "3.0.2" + resolved "https://registry.yarnpkg.com/near-api-js/-/near-api-js-3.0.2.tgz#e5d9a97e248f5885bdd166df30452aef0f252b14" + integrity sha512-o8rgHH5ZV+V9grZTu4GSILupq41JyU3Mt/G6rZ2pBybHA2ozkfp9oIXKRqC4mCkbUtYLy//YoXuLRGLsRDlB2w== + dependencies: + "@near-js/accounts" "1.0.2" + "@near-js/crypto" "1.2.0" + "@near-js/keystores" "0.0.8" + "@near-js/keystores-browser" "0.0.8" + "@near-js/keystores-node" "0.0.8" + "@near-js/providers" "0.0.10" + "@near-js/signers" "0.1.0" + "@near-js/transactions" "1.1.0" + "@near-js/types" "0.0.4" + "@near-js/utils" "0.0.5" + "@near-js/wallet-account" "1.0.2" + "@noble/curves" "1.2.0" + ajv "8.11.2" + ajv-formats "2.1.1" + bn.js "5.2.1" + borsh "1.0.0" + depd "2.0.0" + http-errors "1.7.2" + near-abi "0.1.1" + node-fetch "2.6.7" + near-hd-key@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/near-hd-key/-/near-hd-key-1.2.1.tgz#f508ff15436cf8a439b543220f3cc72188a46756" @@ -16312,6 +16523,13 @@ node-fetch-native@^1.4.0, node-fetch-native@^1.4.1: resolved "https://registry.yarnpkg.com/node-fetch-native/-/node-fetch-native-1.4.1.tgz#5a336e55b4e1b1e72b9927da09fecd2b374c9be5" integrity sha512-NsXBU0UgBxo2rQLOeWNZqS3fvflWePMECr8CoSWoSTqCqGbVVsvl9vZu1HfQicYN0g5piV9Gh8RTEvo/uP752w== +node-fetch@2.6.7, node-fetch@^2.6.7: + version "2.6.7" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" + integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== + dependencies: + whatwg-url "^5.0.0" + node-fetch@^2.6.1, node-fetch@^2.6.8: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" @@ -16319,13 +16537,6 @@ node-fetch@^2.6.1, node-fetch@^2.6.8: dependencies: whatwg-url "^5.0.0" -node-fetch@^2.6.7: - version "2.6.7" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" - integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== - dependencies: - whatwg-url "^5.0.0" - node-forge@^1, node-forge@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3" @@ -18373,7 +18584,7 @@ radix3@^1.1.0: resolved "https://registry.yarnpkg.com/radix3/-/radix3-1.1.0.tgz#9745df67a49c522e94a33d0a93cf743f104b6e0d" integrity sha512-pNsHDxbGORSvuSScqNJ+3Km6QAVqk8CfsCBIEoDgpqLrkD2f3QM4I7d1ozJJ172OmIcoUcerZaNWqtLkRXTV3A== -randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: +randombytes@2.1.0, randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== @@ -19409,6 +19620,11 @@ setprototypeof@1.1.0: resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656" integrity sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ== +setprototypeof@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683" + integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw== + setprototypeof@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" @@ -20452,6 +20668,11 @@ toggle-selection@^1.0.6: resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32" integrity sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ== +toidentifier@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" + integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== + toidentifier@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"