Compare commits

...
Author SHA1 Message Date
Jonas DanielsGitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
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 TankandGitHub 0ab14075d3 Fix wallet image fallback (#3000) 2024-05-10 18:10:52 -07:00
cf7b6fc7bc feat: createWalletAdapter for interop with other libraries (#2997)
Co-authored-by: Manan Tank <[email protected]>
2024-05-10 17:52:08 -07:00
gregandGitHub 523cd1e16f shortenAddress util (#2995) 2024-05-10 23:40:12 +00:00
25 changed files with 179 additions and 13 deletions
+7
View File
@@ -1,5 +1,12 @@
# @thirdweb-dev/auth
## 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.78",
"main": "dist/thirdweb-dev-auth.cjs.js",
"module": "dist/thirdweb-dev-auth.esm.js",
"browser": {
+9
View File
@@ -1,5 +1,14 @@
# thirdweb
## 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.86",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+9
View File
@@ -1,5 +1,14 @@
# @thirdweb-dev/react-core
## 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.19",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react-core",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+9
View File
@@ -1,5 +1,14 @@
# @thirdweb-dev/react
## 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.19",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+7
View File
@@ -1,5 +1,12 @@
# @thirdweb-dev/sdk
## 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.80",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/legacy_packages/sdk",
"license": "Apache-2.0",
@@ -1,5 +1,14 @@
# @thirdweb-dev/unity-js-bridge
## 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.29",
"main": "dist/thirdweb-unity-bridge.js",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
"license": "Apache-2.0",
+7
View File
@@ -1,5 +1,12 @@
# @thirdweb-dev/wallets
## 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.20",
"main": "dist/thirdweb-dev-wallets.cjs.js",
"module": "dist/thirdweb-dev-wallets.esm.js",
"browser": {
+12
View File
@@ -1,5 +1,17 @@
# thirdweb
## 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.0",
"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";
@@ -12,3 +12,6 @@ export const smartWalletIcon =
export const genericTokenIcon =
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzQwNDhfNDIzMSkiPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTcuNTg0IDQuODU1NjZDNy43MTA2OSA0Ljc4MjUyIDcuODU0MzkgNC43NDQwMiA4LjAwMDY3IDQuNzQ0MDJDOC4xNDY5NSA0Ljc0NDAyIDguMjkwNjUgNC43ODI1MiA4LjQxNzM0IDQuODU1NjZMMTAuNTE1MyA2LjA2NjY2QzEwLjY0MiA2LjEzOTggMTAuNzQ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OCAxOCIKICAgICAgd2lkdGg9IjIwIgogICAgICBoZWlnaHQ9IjIwIgogICAgICByb2xlPSJwcmVzZW50YXRpb24iCiAgICA+CiAgICAgIDxwYXRoCiAgICAgICAgZmlsbD0iI2FhYSIKICAgICAgICBkPSJNMTUuNiA0LjZIMS44NXYtLjU1bDEyLjEtLjk2OHYuOTY4aDEuNjVWMi40YzAtMS4yMS0uOTgtMi4wNTktMi4xNzctMS44ODhMMi4zNzggMi4wODlDMS4xOCAyLjI2LjIgMy4zOS4yIDQuNnYxMWEyLjIgMi4yIDAgMDAyLjIgMi4yaDEzLjJhMi4yIDIuMiAwIDAwMi4yLTIuMlY2LjhhMi4yIDIuMiAwIDAwLTIuMi0yLjJ6bS0xLjY1IDcuNzA3YTEuNjUgMS42NSAwIDAxLS42My0zLjE3NiAxLjY1IDEuNjUgMCAxMS42MyAzLjE3NnoiCiAgICAgIC8+CiAgICA8L3N2Zz4=";
@@ -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)}`;
}
@@ -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.