Compare commits

..
Author SHA1 Message Date
7fcd60ec64 Version Packages (#3007)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <[email protected]>
2024-05-13 17:31:23 +12:00
Joaquim Verges 0006e547a4 fix: chain switching with in-app smart accounts (#3005) 2024-05-13 04:16:51 +00:00
Jonas Danielsandgithub-actions[bot] 1ed12557bb Version Packages (#2996)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-10 18:17:33 -07:00
Manan Tank 0ab14075d3 Fix wallet image fallback (#3000) 2024-05-10 18:10:52 -07:00
Joaquim VergesandManan Tank cf7b6fc7bc feat: createWalletAdapter for interop with other libraries (#2997)
Co-authored-by: Manan Tank <[email protected]>
2024-05-10 17:52:08 -07:00
greg 523cd1e16f shortenAddress util (#2995) 2024-05-10 23:40:12 +00:00
38 changed files with 296 additions and 36 deletions
+14
View File
@@ -1,5 +1,19 @@
# @thirdweb-dev/auth
## 4.1.79
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/wallets@2.5.21
## 4.1.78
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/wallets@2.5.20
## 4.1.77
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "4.1.77",
"version": "4.1.79",
"main": "dist/thirdweb-dev-auth.cjs.js",
"module": "dist/thirdweb-dev-auth.esm.js",
"browser": {
+18
View File
@@ -1,5 +1,23 @@
# thirdweb
## 0.13.87
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.81
- @thirdweb-dev/wallets@2.5.21
- @thirdweb-dev/auth@4.1.79
## 0.13.86
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.80
- @thirdweb-dev/wallets@2.5.20
- @thirdweb-dev/auth@4.1.78
## 0.13.85
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/cli",
"main": "dist/cli/index.js",
"version": "0.13.85",
"version": "0.13.87",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+18
View File
@@ -1,5 +1,23 @@
# @thirdweb-dev/react-core
## 4.6.20
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.81
- @thirdweb-dev/wallets@2.5.21
- @thirdweb-dev/auth@4.1.79
## 4.6.19
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.80
- @thirdweb-dev/wallets@2.5.20
- @thirdweb-dev/auth@4.1.78
## 4.6.18
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-core",
"version": "4.6.18",
"version": "4.6.20",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react-core",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+18
View File
@@ -1,5 +1,23 @@
# @thirdweb-dev/react
## 4.6.20
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.81
- @thirdweb-dev/react-core@4.6.20
- @thirdweb-dev/wallets@2.5.21
## 4.6.19
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.80
- @thirdweb-dev/react-core@4.6.19
- @thirdweb-dev/wallets@2.5.20
## 4.6.18
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "4.6.18",
"version": "4.6.20",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
Binary file not shown.
+14
View File
@@ -1,5 +1,19 @@
# @thirdweb-dev/sdk
## 4.0.81
### Patch Changes
- Updated dependencies [[`0006e54`](https://github.com/thirdweb-dev/js/commit/0006e547a4425406101ef85c635b83c5c6186d1d)]:
- thirdweb@5.19.1
## 4.0.80
### Patch Changes
- Updated dependencies [[`0ab1407`](https://github.com/thirdweb-dev/js/commit/0ab14075d37aec27167c5885155f48ea880c9574), [`523cd1e`](https://github.com/thirdweb-dev/js/commit/523cd1e16fd1194ffbf8970150ed6f09d4e01fe9), [`cf7b6fc`](https://github.com/thirdweb-dev/js/commit/cf7b6fc7bc1686f3b4c54515d569d799d5e3ceea)]:
- thirdweb@5.19.0
## 4.0.79
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "4.0.79",
"version": "4.0.81",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/sdk",
"license": "Apache-2.0",
Binary file not shown.
@@ -1,5 +1,23 @@
# @thirdweb-dev/unity-js-bridge
## 0.6.30
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.81
- @thirdweb-dev/wallets@2.5.21
- @thirdweb-dev/auth@4.1.79
## 0.6.29
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.80
- @thirdweb-dev/wallets@2.5.20
- @thirdweb-dev/auth@4.1.78
## 0.6.28
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/unity-js-bridge",
"version": "0.6.28",
"version": "0.6.30",
"main": "dist/thirdweb-unity-bridge.js",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
"license": "Apache-2.0",
+14
View File
@@ -1,5 +1,19 @@
# @thirdweb-dev/wallets
## 2.5.21
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.81
## 2.5.20
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@4.0.80
## 2.5.19
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/wallets",
"version": "2.5.19",
"version": "2.5.21",
"main": "dist/thirdweb-dev-wallets.cjs.js",
"module": "dist/thirdweb-dev-wallets.esm.js",
"browser": {
+20
View File
@@ -1,5 +1,25 @@
# thirdweb
## 5.19.1
### Patch Changes
- [#3005](https://github.com/thirdweb-dev/js/pull/3005) [`0006e54`](https://github.com/thirdweb-dev/js/commit/0006e547a4425406101ef85c635b83c5c6186d1d) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - - useSendTransaction now switches chain if needed
- Fix chain switching with in-app smart accounts
- Fix tx simulation for pay modal
## 5.19.0
### Minor Changes
- [#2995](https://github.com/thirdweb-dev/js/pull/2995) [`523cd1e`](https://github.com/thirdweb-dev/js/commit/523cd1e16fd1194ffbf8970150ed6f09d4e01fe9) Thanks [@gregfromstl](https://github.com/gregfromstl)! - Adds shortenAddress util
- [#2997](https://github.com/thirdweb-dev/js/pull/2997) [`cf7b6fc`](https://github.com/thirdweb-dev/js/commit/cf7b6fc7bc1686f3b4c54515d569d799d5e3ceea) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - added `createWalletAdapter` helper for interop with diff libraries
### Patch Changes
- [#3000](https://github.com/thirdweb-dev/js/pull/3000) [`0ab1407`](https://github.com/thirdweb-dev/js/commit/0ab14075d37aec27167c5885155f48ea880c9574) Thanks [@MananTank](https://github.com/MananTank)! - Fix WalletImage fallback icon
## 5.18.1
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "thirdweb",
"version": "5.18.1",
"version": "5.19.1",
"repository": {
"type": "git",
"url": "git+https://github.com/thirdweb-dev/js.git#main"
@@ -0,0 +1,49 @@
import type { Chain } from "../chains/types.js";
import type { ThirdwebClient } from "../client/client.js";
import type { Account, Wallet } from "../wallets/interfaces/wallet.js";
import { createWalletEmitter } from "../wallets/wallet-emitter.js";
export type AdapterWalletOptions = {
client: ThirdwebClient;
adaptedAccount: Account;
chain: Chain;
onDisconnect: () => Promise<void> | void;
switchChain: (chain: Chain) => Promise<void> | void;
};
export function createWalletAdapter(
options: AdapterWalletOptions,
): Wallet<"adapter"> {
const emitter = createWalletEmitter<"adapter">();
let _chain = options.chain;
return {
id: "adapter",
subscribe: emitter.subscribe,
connect: async () => {
emitter.emit("onConnect", options);
return options.adaptedAccount;
},
autoConnect: async () => {
emitter.emit("onConnect", options);
return options.adaptedAccount;
},
disconnect: async () => {
await options.onDisconnect();
emitter.emit("disconnect", undefined);
},
getAccount() {
return options.adaptedAccount;
},
getChain() {
return _chain;
},
getConfig() {
return options;
},
switchChain: async (chain) => {
await options.switchChain(chain);
_chain = chain;
emitter.emit("chainChanged", chain);
},
};
}
+1
View File
@@ -124,6 +124,7 @@ export {
checksumAddress,
getAddress,
isAddress,
shortenAddress,
type Address,
type AddressInput,
} from "../utils/address.js";
+2
View File
@@ -96,3 +96,5 @@ export type {
export { getAllWalletsList } from "../wallets/getAllWalletsList.js";
export { getWalletInfo } from "../wallets/__generated__/getWalletInfo.js";
export { createWalletAdapter } from "../adapters/wallet-adapter.js";
@@ -5,12 +5,17 @@ import { sendTransaction } from "../../../../transaction/actions/send-transactio
import type { WaitForReceiptOptions } from "../../../../transaction/actions/wait-for-tx-receipt.js";
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
import type { Account } from "../../../../wallets/interfaces/wallet.js";
import {
type GetWalletBalanceResult,
getWalletBalance,
} from "../../../../wallets/utils/getWalletBalance.js";
import { fetchBuySupportedDestinations } from "../../../web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js";
import { useActiveAccount } from "../wallets/wallet-hooks.js";
import {
useActiveAccount,
useActiveWallet,
useSwitchActiveWalletChain,
} from "../wallets/wallet-hooks.js";
type ShowModalData = {
tx: PreparedTransaction;
@@ -37,10 +42,21 @@ export function useSendTransactionCore(
showPayModal?: (data: ShowModalData) => void,
gasless?: GaslessOptions,
): UseMutationResult<WaitForReceiptOptions, Error, PreparedTransaction> {
const account = useActiveAccount();
let _account = useActiveAccount();
const wallet = useActiveWallet();
const switchChain = useSwitchActiveWalletChain();
return useMutation({
mutationFn: async (tx) => {
// switch chain if needed
if (wallet && tx.chain.id !== wallet.getChain()?.id) {
await switchChain(tx.chain);
// in smart wallet case, account may change after chain switch
_account = wallet.getAccount();
}
const account = _account;
if (!account) {
throw new Error("No active account");
}
@@ -90,7 +106,7 @@ export function useSendTransactionCore(
chain: tx.chain,
client: tx.client,
}),
getTotalTxCostForBuy(tx),
getTotalTxCostForBuy(tx, account),
]);
const walletBalanceWei = walletBalance.value;
@@ -122,9 +138,13 @@ export function useSendTransactionCore(
});
}
export async function getTotalTxCostForBuy(tx: PreparedTransaction) {
export async function getTotalTxCostForBuy(
tx: PreparedTransaction,
account?: Account,
) {
const gasCost = await estimateGasCost({
transaction: tx,
account,
});
const bufferCost = gasCost.wei / 10n;
@@ -102,7 +102,7 @@ export function ConnectButton(props: ConnectButtonProps) {
wallets: wallets,
locale: props.locale || "en_US",
connectLocale: localeQuery.data,
chain: props.chain,
chain: props.chain || props.accountAbstraction?.chain,
chains: props.chains,
walletConnect: props.walletConnect,
accountAbstraction: props.accountAbstraction,
@@ -389,7 +389,7 @@ export function ConnectEmbed(props: ConnectEmbedProps) {
wallets: wallets,
locale: localeId,
connectLocale: localeQuery.data,
chain: props.chain,
chain: props.chain || props.accountAbstraction?.chain,
chains: props.chains,
walletConnect: props.walletConnect,
accountAbstraction: props.accountAbstraction,
@@ -12,3 +12,6 @@ export const smartWalletIcon =
export const genericTokenIcon =
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzQwNDhfNDIzMSkiPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTcuNTg0IDQuODU1NjZDNy43MTA2OSA0Ljc4MjUyIDcuODU0MzkgNC43NDQwMiA4LjAwMDY3IDQuNzQ0MDJDOC4xNDY5NSA0Ljc0NDAyIDguMjkw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HR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgICAgIGZpbGw9Im5vbmUiCiAgICAgIHZpZXdCb3g9IjAgMCAxOCAxOCIKICAgICAgd2lkdGg9IjIwIgogICAgICBoZWlnaHQ9IjIwIgogICAgICByb2xlPSJwcmVzZW50YXRpb24iCiAgICA+CiAgICAgIDxwYXRoCiAgICAgICAgZmlsbD0iI2FhYSIKICAgICAgICBkPSJNMTUuNiA0LjZIMS44NXYtLjU1bDEyLjEtLjk2OHYuOTY4aDEuNjVWMi40YzAtMS4yMS0uOTgtMi4wNTktMi4xNzctMS44ODhMMi4zNzggMi4wODlDMS4xOCAyLjI2LjIgMy4zOS4yIDQuNnYxMWEyLjIgMi4yIDAgMDAyLjIgMi4yaDEzLjJhMi4yIDIuMiAwIDAwMi4yLTIuMlY2LjhhMi4yIDIuMiAwIDAwLTIuMi0yLjJ6bS0xLjY1IDcuNzA3YTEuNjUgMS42NSAwIDAxLS42My0zLjE3NiAxLjY1IDEuNjUgMCAxMS42MyAzLjE3NnoiCiAgICAgIC8+CiAgICA8L3N2Zz4=";
@@ -217,6 +217,7 @@ function BuyScreenContent(props: BuyScreenContentProps) {
buyForTx,
hasEditedAmount,
isMainScreen: screen.type === "main",
account,
});
// check if the screen is expanded or not
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { formatNumber } from "../../../../../../../utils/formatNumber.js";
import { toEther } from "../../../../../../../utils/units.js";
import type { Account } from "../../../../../../../wallets/interfaces/wallet.js";
import { getTotalTxCostForBuy } from "../../../../../../core/hooks/contract/useSendTransaction.js";
import { wait } from "../../../../../../core/utils/wait.js";
import type { BuyForTx } from "./types.js";
@@ -10,8 +11,10 @@ export function useBuyTxStates(options: {
buyForTx?: BuyForTx;
hasEditedAmount: boolean;
isMainScreen: boolean;
account?: Account;
}) {
const { buyForTx, hasEditedAmount, isMainScreen, setTokenAmount } = options;
const { buyForTx, hasEditedAmount, isMainScreen, setTokenAmount, account } =
options;
const shouldRefreshTokenAmount = !hasEditedAmount && isMainScreen;
const stopUpdatingAll = !isMainScreen;
@@ -35,7 +38,7 @@ export function useBuyTxStates(options: {
}
try {
const totalCost = await getTotalTxCostForBuy(buyForTx.tx);
const totalCost = await getTotalTxCostForBuy(buyForTx.tx, account);
if (!mounted) {
return;
@@ -64,7 +67,13 @@ export function useBuyTxStates(options: {
return () => {
mounted = false;
};
}, [buyForTx, shouldRefreshTokenAmount, setTokenAmount, stopUpdatingAll]);
}, [
buyForTx,
shouldRefreshTokenAmount,
setTokenAmount,
stopUpdatingAll,
account,
]);
return {
amountNeeded,
@@ -8,11 +8,7 @@ import {
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
import type { TransactionReceipt } from "../../../../transaction/types.js";
import { stringify } from "../../../../utils/json.js";
import {
useActiveAccount,
useActiveWallet,
useSwitchActiveWalletChain,
} from "../../../core/hooks/wallets/wallet-hooks.js";
import { useActiveAccount } from "../../../core/hooks/wallets/wallet-hooks.js";
import {
type SendTransactionPayModalConfig,
useSendTransaction,
@@ -131,9 +127,7 @@ export function TransactionButton(props: TransactionButtonProps) {
...buttonProps
} = props;
const account = useActiveAccount();
const wallet = useActiveWallet();
const [isPending, setIsPending] = useState(false);
const switchChain = useSwitchActiveWalletChain();
const sendTransaction = useSendTransaction({
gasless,
@@ -153,11 +147,6 @@ export function TransactionButton(props: TransactionButtonProps) {
try {
setIsPending(true);
const resolvedTx = await transaction();
if (wallet && wallet.getChain()?.id !== resolvedTx.chain.id) {
await switchChain(resolvedTx.chain);
}
const result = await sendTransaction.mutateAsync(resolvedTx);
if (onTransactionSent) {
@@ -27,7 +27,7 @@ export const Img: React.FC<{
const widthPx = `${props.width}px`;
const heightPx = `${props.height || props.width}px`;
if (!propSrc) {
if (propSrc === undefined) {
return <Skeleton width={widthPx} height={heightPx} />;
}
@@ -7,7 +7,11 @@ import type { WalletId } from "../../../../wallets/wallet-types.js";
import { useActiveWallet } from "../../../core/hooks/wallets/wallet-hooks.js";
import { getStorage } from "../../../core/storage.js";
import { getLastAuthProvider } from "../../wallets/in-app/storage.js";
import { emailIcon, phoneIcon } from "../ConnectWallet/icons/dataUris.js";
import {
emailIcon,
genericWalletIcon,
phoneIcon,
} from "../ConnectWallet/icons/dataUris.js";
import {
appleIconUri,
facebookIconUri,
@@ -81,6 +85,7 @@ export function WalletImage(props: {
return (
<Img
src={image}
fallbackImage={genericWalletIcon}
width={props.size}
height={props.size}
loading="eager"
@@ -107,7 +112,8 @@ function WalletImageQuery(props: {
return (
<Img
client={props.client}
src={walletImage.data}
src={walletImage.isLoading ? undefined : walletImage.data || ""}
fallbackImage={genericWalletIcon}
width={props.size}
height={props.size}
loading="eager"
+14 -1
View File
@@ -1,6 +1,11 @@
import { describe, expect, test } from "vitest";
import { checksumAddress, getAddress, isAddress } from "./address.js";
import {
checksumAddress,
getAddress,
isAddress,
shortenAddress,
} from "./address.js";
describe("getAddress", () => {
test("checksums address", () => {
@@ -81,3 +86,11 @@ describe("checksumAddress", () => {
).toMatchInlineSnapshot('"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65"');
});
});
describe("shortenAddress", () => {
test("shortens address", () => {
expect(
shortenAddress("0xa0cf798816d4b9b9866b5330eea46a18382f251e"),
).toMatchInlineSnapshot('"0xA0...251e"');
});
});
+19
View File
@@ -95,3 +95,22 @@ export function getAddress(address: string): Address {
}
return checksumAddress(address);
}
/**
* Checksums and formats an address if valid. Note this function does not check if the provided address is an ENS.
* @param address - The address to shorten.
* @param length - The number of characters to keep from the start and end of the address.
* @returns The shortened address.
* @example
* ```ts
* import { shortenAddress } from 'thirdweb/utils';
*
* shortenAddress('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed');
* //=> '0x5aAe...Ef1BeAed'
* ```
* @utils
*/
export function shortenAddress(address: Address, length = 4) {
const _address = getAddress(address);
return `${_address.slice(0, length)}...${_address.slice(-length)}`;
}
@@ -25,10 +25,14 @@ export async function connectInAppWallet(
client: options.client,
authAccount,
smartAccountOptions: createOptions.smartAccount,
chain: options.chain,
});
}
return [authAccount, options.chain || ethereum] as const;
return [
authAccount,
options.chain || createOptions?.smartAccount?.chain || ethereum,
] as const;
}
/**
@@ -51,16 +55,21 @@ export async function autoConnectInAppWallet(
client: options.client,
authAccount,
smartAccountOptions: createOptions.smartAccount,
chain: options.chain,
});
}
return [authAccount, options.chain || ethereum] as const;
return [
authAccount,
options.chain || createOptions?.smartAccount?.chain || ethereum,
] as const;
}
async function convertToSmartAccount(options: {
client: ThirdwebClient;
authAccount: Account;
smartAccountOptions: CreateWalletArgs<"smart">[1];
chain?: Chain;
}) {
const [{ smartWallet }, { connectSmartWallet }] = await Promise.all([
import("../../../create-wallet.js"),
@@ -73,6 +82,7 @@ async function convertToSmartAccount(options: {
{
client: options.client,
personalAccount: options.authAccount,
chain: options.chain,
},
options.smartAccountOptions,
);
@@ -1,3 +1,4 @@
import type { AdapterWalletOptions } from "../adapters/wallet-adapter.js";
import type { Chain } from "../chains/types.js";
import type { ThirdwebClient } from "../client/client.js";
import type {
@@ -28,6 +29,7 @@ export type WalletId =
| "inApp"
| "embedded" // deprecated
| "smart"
| "adapter"
| WCSupportedWalletIds
| InjectedSupportedWalletIds;
@@ -116,7 +118,9 @@ export type WalletCreationOptions<T extends WalletId> = T extends "smart"
? InAppWalletCreationOptions
: T extends typeof COINBASE
? CoinbaseWalletCreationOptions
: undefined;
: T extends "adapter"
? AdapterWalletOptions
: undefined;
/**
* Generic type for getting the tuple type of arguments that the `createWallet` function takes.
Binary file not shown.