diff --git a/package-lock.json b/package-lock.json index fbbd36858..8fd55ef88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3288,9 +3288,9 @@ } }, "node_modules/@cere/torus-embed": { - "version": "0.2.9", - "resolved": "https://registry.npmjs.org/@cere/torus-embed/-/torus-embed-0.2.9.tgz", - "integrity": "sha512-z7qCdjNujRVVtgiBxZqi328zsAtx9iVmaYyEXof/euHf31tlYXbnF0/sLdGIs1JsHwfXHQEiN42QnHCvpDksDg==", + "version": "0.2.10", + "resolved": "https://registry.npmjs.org/@cere/torus-embed/-/torus-embed-0.2.10.tgz", + "integrity": "sha512-bp+zLkl5zDnsWFf5q6r0463d00P6MoCNCyQAGYRvuxwRaghmqxpU+RWUD6uTYyaVAKF5AR8Gjn5izI8DCO7BSg==", "dependencies": { "@metamask/obs-store": "^7.0.0", "@toruslabs/http-helpers": "^3.2.0", @@ -36993,10 +36993,10 @@ }, "packages/embed-wallet": { "name": "@cere/embed-wallet", - "version": "0.23.2", + "version": "0.23.3", "license": "Apache-2.0", "dependencies": { - "@cere/torus-embed": "0.2.9", + "@cere/torus-embed": "0.2.10", "@types/bn.js": "^5.1.1", "@types/readable-stream": "^2.3.15", "bn.js": "^5.2.1" @@ -37004,7 +37004,7 @@ }, "packages/embed-wallet-inject": { "name": "@cere/embed-wallet-inject", - "version": "0.23.2", + "version": "0.23.3", "license": "Apache-2.0", "dependencies": { "@polkadot/extension-inject": "^0.46.6" diff --git a/packages/communication/src/wallet/channels.ts b/packages/communication/src/wallet/channels.ts index 1fb5a4859..1c7dc5b62 100644 --- a/packages/communication/src/wallet/channels.ts +++ b/packages/communication/src/wallet/channels.ts @@ -2,7 +2,7 @@ import type { Context, NetworkConfig } from '@cere/embed-wallet'; import type { PermissionRequest, BiconomyOptions } from '@cere-wallet/wallet-engine'; import { createChannel, CreateChannelOptions } from './createChannel'; -import { AuthMethod } from '@cere/torus-embed'; +import { AuthMethod, WalletMode } from '@cere/torus-embed'; export type UserInfo = { email: string; @@ -44,6 +44,7 @@ export type InitChannelIn = { network: NetworkInterface; biconomy?: BiconomyOptions; authMethod?: AuthMethod; + mode?: WalletMode; }; }; diff --git a/packages/embed-wallet-inject/package.json b/packages/embed-wallet-inject/package.json index 0ebf11003..5c2f84394 100644 --- a/packages/embed-wallet-inject/package.json +++ b/packages/embed-wallet-inject/package.json @@ -1,6 +1,6 @@ { "name": "@cere/embed-wallet-inject", - "version": "0.23.2", + "version": "0.23.3", "sideEffects": false, "type": "module", "types": "./dist/types/index.d.ts", diff --git a/packages/embed-wallet/package.json b/packages/embed-wallet/package.json index efa43e75a..0bde08ab6 100644 --- a/packages/embed-wallet/package.json +++ b/packages/embed-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@cere/embed-wallet", - "version": "0.23.2", + "version": "0.23.3", "description": "Cere Wallet SDK to integrate the wallet into a web application.", "sideEffects": false, "main": "dist/bundle.umd.js", @@ -23,7 +23,7 @@ }, "license": "Apache-2.0", "dependencies": { - "@cere/torus-embed": "0.2.9", + "@cere/torus-embed": "0.2.10", "@types/bn.js": "^5.1.1", "@types/readable-stream": "^2.3.15", "bn.js": "^5.2.1" diff --git a/packages/embed-wallet/src/EmbedWallet.ts b/packages/embed-wallet/src/EmbedWallet.ts index f7cc1b73d..a3dc877f3 100644 --- a/packages/embed-wallet/src/EmbedWallet.ts +++ b/packages/embed-wallet/src/EmbedWallet.ts @@ -158,6 +158,7 @@ export class EmbedWallet { context, biconomy, authMethod, + mode, popupMode = 'modal', connectOptions = {}, appId = this.options.appId, @@ -188,6 +189,7 @@ export class EmbedWallet { check: false, version: clientVersion, }, + mode, }); this.proxyProvider.setTarget(this.torus.provider); diff --git a/packages/embed-wallet/src/types.ts b/packages/embed-wallet/src/types.ts index 20be9f37a..232abba29 100644 --- a/packages/embed-wallet/src/types.ts +++ b/packages/embed-wallet/src/types.ts @@ -1,4 +1,4 @@ -import type { AuthMethod, NetworkInterface } from '@cere/torus-embed'; +import type { AuthMethod, NetworkInterface, WalletMode } from '@cere/torus-embed'; import BN from 'bn.js'; // App context @@ -89,6 +89,7 @@ export type WalletOptions = { sessionNamespace?: string; clientVersion?: string; env?: WalletEnvironment; + mode?: WalletMode; }; export type BiconomyOptions = { diff --git a/packages/wallet-engine/src/engine/polkadot.ts b/packages/wallet-engine/src/engine/polkadot.ts index 5fce2038d..3423d9cfb 100644 --- a/packages/wallet-engine/src/engine/polkadot.ts +++ b/packages/wallet-engine/src/engine/polkadot.ts @@ -193,7 +193,14 @@ export const createPolkadotEngine = ({ getPrivateKey, polkadotRpc }: PolkadotEng const secretKeyCurve25519 = convertSecretKey(secretKey); - res.result = u8aToHex(nacl.box(new TextEncoder().encode(u8aToHex(dek)), new Uint8Array(24), theirPublicKeyCurve25519, secretKeyCurve25519)); + res.result = u8aToHex( + nacl.box( + new TextEncoder().encode(u8aToHex(dek)), + new Uint8Array(24), + theirPublicKeyCurve25519, + secretKeyCurve25519, + ), + ); }), ed25519_getBalance: createAsyncMiddleware(async (req, res) => { diff --git a/packages/wallet-engine/src/engine/provider.ts b/packages/wallet-engine/src/engine/provider.ts index d56feb599..94b80f2d4 100644 --- a/packages/wallet-engine/src/engine/provider.ts +++ b/packages/wallet-engine/src/engine/provider.ts @@ -11,6 +11,7 @@ import type { EthereumEngineOptions } from './ethereum'; import type { PolkadotEngineOptions } from './polkadot'; import type { AccountsEngineOptions } from './accounts'; import type { SolanaEngineOptions } from './solana'; +import { WalletMode } from '@cere/torus-embed'; export type ProviderEngineOptions = WalletEngineOptions & AccountsEngineOptions & @@ -53,6 +54,10 @@ class ChainEngine extends Engine { return createPolkadotEngine(options); }); + if (options.mode == 'light') { + return; + } + this.pushEngine( import(/* webpackChunkName: "accountsEngine" */ './solana').then(({ createSolanaEngine }) => createSolanaEngine(options), @@ -74,9 +79,11 @@ class ChainEngine extends Engine { export class ProviderEngine extends Engine { readonly provider: Provider; readonly unsafeProvider; + private readonly mode?: WalletMode; constructor(options: ProviderEngineOptions) { super(); + this.mode = options.mode; const unsafeEngine = new Engine(); const walletEngine = createWalletEngine(options); @@ -103,6 +110,10 @@ export class ProviderEngine extends Engine { async updateAccounts() { const [eth, ed25519] = await this.provider.request({ method: 'wallet_updateAccounts' }); + if (this.mode == 'light') { + return; + } + /** * TODO: Move balance subscriptions to the Wallet SDK to make them lazy started */ diff --git a/packages/wallet-engine/src/engine/wallet.ts b/packages/wallet-engine/src/engine/wallet.ts index 4fda22db6..7e3fe4070 100644 --- a/packages/wallet-engine/src/engine/wallet.ts +++ b/packages/wallet-engine/src/engine/wallet.ts @@ -2,11 +2,13 @@ import { createScaffoldMiddleware, createAsyncMiddleware } from 'json-rpc-engine import { Engine } from './engine'; import { Account, ChainConfig } from '../types'; +import { WalletMode } from '@cere/torus-embed'; export type WalletEngineOptions = { getAccounts: () => Account[]; getPrivateKey: () => string | undefined; chainConfig: ChainConfig; + mode?: WalletMode; }; export const createWalletEngine = ({ chainConfig, getAccounts, getPrivateKey }: WalletEngineOptions) => { diff --git a/src/stores/CollectiblesStore/CollectionStore.ts b/src/stores/CollectiblesStore/CollectionStore.ts index 5e6e0683d..81708e59e 100644 --- a/src/stores/CollectiblesStore/CollectionStore.ts +++ b/src/stores/CollectiblesStore/CollectionStore.ts @@ -16,7 +16,7 @@ export class CollectiblesStore { reaction( () => wallet.account?.address, async (address) => { - if (address) { + if (address && wallet.mode !== 'light') { await this.updateNfts(address); } else { this._nfts = []; diff --git a/src/stores/EmbededWalletStore/EmbeddedWalletStore.ts b/src/stores/EmbededWalletStore/EmbeddedWalletStore.ts index d78bb07ac..0c7d1f27f 100644 --- a/src/stores/EmbededWalletStore/EmbeddedWalletStore.ts +++ b/src/stores/EmbededWalletStore/EmbeddedWalletStore.ts @@ -1,6 +1,6 @@ import { randomBytes } from 'crypto'; import { providers } from 'ethers'; -import { makeAutoObservable, reaction, toJS, when } from 'mobx'; +import { makeAutoObservable, reaction, toJS, when, runInAction } from 'mobx'; import { createWalletEngine, WalletEngine, BiconomyOptions } from '@cere-wallet/wallet-engine'; import { createWalletConnection, createRpcConnection, WalletConnection } from '@cere-wallet/communication'; @@ -20,9 +20,11 @@ import { BICONOMY_API_KEY, CERE_NETWORK_RPC, RPC_POLLING_INTERVAL } from '~/cons import { ApplicationsStore } from '../ApplicationsStore'; import { SessionStore } from '../SessionStore'; import { PermissionsStore } from '../PermissionsStore'; +import { WalletMode } from '@cere/torus-embed'; type InitOptions = { biconomy?: BiconomyOptions; + mode?: WalletMode; }; export class EmbeddedWalletStore implements Wallet { @@ -151,6 +153,10 @@ export class EmbeddedWalletStore implements Wallet { return this.accountStore.accounts; } + get mode() { + return this.options.mode; + } + async init() { await this.setupWalletConnection(); await this.setupRpcConnection(); @@ -160,19 +166,23 @@ export class EmbeddedWalletStore implements Wallet { this.walletConnection = createWalletConnection({ logger: console, - onInit: async ({ chainConfig, context, biconomy, authMethod }) => { + onInit: async ({ chainConfig, context, biconomy, authMethod, mode }) => { this.networkStore.network = chainConfig; this.appContextStore.context = context; if (authMethod) { this.appContextStore.authMethod = authMethod; } - /** - * Configure the wallet with the init options - */ - if (biconomy) { - this.options.biconomy = biconomy; - } + runInAction(() => { + /** + * Configure the wallet with the init options + */ + if (biconomy) { + this.options.biconomy = biconomy; + } + + this.options.mode = mode || 'default'; + }); return true; }, @@ -273,10 +283,10 @@ export class EmbeddedWalletStore implements Wallet { await when(() => !!this.networkStore.network); this.engine = createWalletEngine({ - pollingInterval: RPC_POLLING_INTERVAL, chainConfig: this.networkStore.network!, polkadotRpc: CERE_NETWORK_RPC, biconomy: this.options.biconomy, + mode: this.options.mode, getPrivateKey: () => this.accountStore.privateKey, getAccounts: () => toJS(this.accountStore.accounts), onUpdateAccounts: (keyPairs) => this.accountStore.updateAccounts(keyPairs), diff --git a/src/stores/ExchangeRatesStore/ExchangeRatesStore.ts b/src/stores/ExchangeRatesStore/ExchangeRatesStore.ts index 22e15e72d..835a46631 100644 --- a/src/stores/ExchangeRatesStore/ExchangeRatesStore.ts +++ b/src/stores/ExchangeRatesStore/ExchangeRatesStore.ts @@ -19,12 +19,20 @@ export class ExchangeRatesStore { this.interval = DEFAULT_INTERVAL; when( () => this.assetStore.commonList.length > 0, - () => this.updateExchangeRates(), + () => { + if (wallet.mode !== 'light') { + this.updateExchangeRates(); + } + }, ); when( - () => !!wallet.network?.chainId, - () => this.updateExchangeRates(), + () => !!wallet.network?.chainId && !!wallet.mode, + () => { + if (wallet.mode !== 'light') { + this.updateExchangeRates(); + } + }, ); } diff --git a/src/stores/NetworkStore/NetworkStore.ts b/src/stores/NetworkStore/NetworkStore.ts index 90d1e4701..c45ef139f 100644 --- a/src/stores/NetworkStore/NetworkStore.ts +++ b/src/stores/NetworkStore/NetworkStore.ts @@ -23,7 +23,7 @@ export class NetworkStore { makeAutoObservable(this); autorun(async () => { - if (wallet.isReady()) { + if (wallet.isReady() && wallet.mode !== 'light') { this.gasPrice = await this.wallet.provider?.getGasPrice()!; } else { this.gasPrice = undefined; diff --git a/src/stores/types.ts b/src/stores/types.ts index 9a133f114..d51d1520d 100644 --- a/src/stores/types.ts +++ b/src/stores/types.ts @@ -1,6 +1,7 @@ import { ChainConfig, Account, WalletEngine } from '@cere-wallet/wallet-engine'; import { ethers } from 'ethers'; import { ReactElement } from 'react'; +import { WalletMode } from '@cere/torus-embed'; export type PriceData = { amount: number; @@ -58,6 +59,7 @@ export interface Wallet { readonly engine?: WalletEngine; readonly account?: Account; readonly accounts: Account[]; + readonly mode?: WalletMode; /** * Provider instance with blockchain requests protected by confirmation modals