@thirdweb-dev/wallets
Version:
<p align="center"> <br /> <a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/legacy_packages/sdk/logo.svg?raw=true" width="200" alt=""/></a> <br /> </p> <h1 align="center">thirdweb Wallet SDK</h1> <p align="center"> <a h
182 lines (172 loc) • 5.34 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var defineProperty = require('../../../../dist/defineProperty-b749763b.cjs.prod.js');
var evm_wallets_base_dist_thirdwebDevWalletsEvmWalletsBase = require('../../../../dist/base-5085b4d0.cjs.prod.js');
var walletIds = require('../../../../dist/walletIds-6ed32bf4.cjs.prod.js');
require('@thirdweb-dev/chains');
require('../../abstract/dist/thirdweb-dev-wallets-evm-wallets-abstract.cjs.prod.js');
require('ethers');
require('eventemitter3');
require('@thirdweb-dev/sdk');
require('../../../../dist/headers-140df57f.cjs.prod.js');
// re-export the connection args for convenience
/**
* Wallet interface to connect [Safe wallet](https://safe.global/wallet).
*
* **To connect to a safe wallet, a personal wallet must first be connected.**
*
* @example
* ```javascript
* import { CoinbaseWallet, SafeWallet } from "@thirdweb-dev/wallets";
* import { Ethereum } from "@thirdweb-dev/chains";
*
* // First, connect the personal wallet
* const personalWallet = new CoinbaseWallet();
* await personalWallet.connect();
*
* // Then, connect the Safe wallet
* const wallet = new SafeWallet();
* await wallet.connect({
* personalWallet: personalWallet,
* chain: Ethereum,
* safeAddress: "{{contract_address}}",
* });
* ```
*
* @wallet
*/
class SafeWallet extends evm_wallets_base_dist_thirdwebDevWalletsEvmWalletsBase.AbstractClientWallet {
/**
* @internal
*/
get walletName() {
return "Safe Wallet";
}
/**
* Create a `SafeWallet` instance.
* @param options -
* The `options` object includes the following properties:
*
* ### clientId (recommended)
*
* Provide `clientId` to use the thirdweb RPCs for given `chains`
*
* You can create a client ID for your application from [thirdweb dashboard](https://thirdweb.com/create-api-key).
*
* ### chains (optional)
*
* Provide an array of chains you want to support.
*
* Must be an array of `Chain` objects, from the [`@thirdweb-dev/chains`](https://www.npmjs.com/package/\@thirdweb-dev/chains) package.
*
* Defaults to our [default chains](/react/react.thirdwebprovider#default-chains).
*
* ### dappMetadata (optional)
*
* Information about your app that the wallet will display when your app tries to connect to it.
*
* Must be an object containing `name`, `url`, `description` and `logoUrl` properties.
*
* ```javascript
* import { SafeWallet } from "@thirdweb-dev/wallets";
*
* const walletWithOptions = new SafeWallet({
* dappMetadata: {
* name: "thirdweb powered dApp",
* url: "https://thirdweb.com",
* description: "thirdweb powered dApp",
* logoUrl: "https://thirdweb.com/favicon.ico",
* }
* });
* ```
*
*/
constructor(options) {
super(SafeWallet.id, {
...options
});
}
async getConnector() {
if (!this.connector) {
const {
SafeConnector
} = await Promise.resolve().then(function () { return require('../../../connectors/safe/dist/thirdweb-dev-wallets-evm-connectors-safe.cjs.prod.js'); });
this.connector = new SafeConnector();
}
return this.connector;
}
/**
* Get the personal wallet that is connected to the Safe wallet.
* @returns
*/
getPersonalWallet() {
return this.connector?.personalWallet;
}
/**
* Auto connect the wallet if it was previously connected.
*/
autoConnect(params) {
return this.connect(params);
}
/**
* Connect Safe wallet
* @param connectOptions -
* The `connectOptions` object includes the following properties:
*
* @example
* ```javascript
* import { CoinbaseWallet, SafeWallet } from "@thirdweb-dev/wallets";
* import { Ethereum } from "@thirdweb-dev/chains";
*
* // First, connect the personal wallet
* const personalWallet = new CoinbaseWallet();
* await personalWallet.connect();
*
* // Then, connect the Safe wallet
* const wallet = new SafeWallet();
* await wallet.connect({
* personalWallet: personalWallet, // Wallet that can sign transactions on the Safe
* chain: Ethereum, // Chain that the Safe is on
* safeAddress: "{{contract_address}}", // Smart contract address of the Safe
* });
* ```
*
* ### personalWallet
*
* The instance of a personal wallet that can sign transactions on the Safe.
*
* Must be of type `EVMWallet` such as [`CoinbaseWallet`](/wallet/coinbase-wallet) or [`MetamaskWallet`](/wallet/metamask).
*
* ### chain
*
* The chain that the Safe smart contract is deployed to.
*
* Must be a `Chain` object, from the [`@thirdweb-dev/chains`](https://www.npmjs.com/package/\@thirdweb-dev/chains) package.
*
* ### safeAddress
*
* Smart contract address of the Safe wallet.
*
* Must be a `string`.
*
* @returns A Promise that resolves to the Safe address.
*/
connect(connectOptions) {
return super.connect(connectOptions);
}
}
/**
* @internal
*/
/**
* @internal
*/
defineProperty._defineProperty(SafeWallet, "meta", {
name: "Safe",
iconURL: "ipfs://QmbbyxDDmmLQh8DzzeUR6X6B75bESsNUFmbdvS3ZsQ2pN1/SafeToken.svg"
});
/**
* @internal
*/
defineProperty._defineProperty(SafeWallet, "id", walletIds.walletIds.safe);
exports.SafeWallet = SafeWallet;