Skip to content

Commit 7480539

Browse files
committed
Fix svg and url handiling
1 parent 0993aec commit 7480539

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",

packages/core/src/utils.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ export function validEnsChain(chainId: ChainId): boolean {
3636
}
3737
}
3838

39-
export function isUrl(str: string): boolean {
40-
let url
41-
42-
try {
43-
url = new URL(str)
44-
} catch (_) {
45-
return false
46-
}
47-
48-
return url.protocol === 'http:' || url.protocol === 'https:'
39+
export function isSVG(str: string): boolean {
40+
return str.includes('<svg')
4941
}

packages/core/src/views/connect/Sidebar.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { internalState$ } from '../../streams'
55
import en from '../../i18n/en.json'
66
import type { i18n } from '../../types'
7-
import { isUrl } from '../../utils'
7+
import { isSVG } from '../../utils'
88
99
export let step: keyof i18n['connect']
1010
@@ -111,10 +111,10 @@
111111
<div class="inner-container">
112112
<div class="icon-container">
113113
{#if logo || icon}
114-
{#if isUrl(logo || icon)}
115-
<img height="100%" src={logo || icon} alt="logo" />
116-
{:else}
114+
{#if isSVG(logo || icon)}
117115
{@html logo || icon}
116+
{:else}
117+
<img height="100%" src={logo || icon} alt="logo" />
118118
{/if}
119119
{:else}
120120
{@html blocknative}

packages/core/src/views/shared/WalletAppBadge.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { fade } from 'svelte/transition'
3-
import { isUrl } from '../../utils'
3+
import { isSVG } from '../../utils'
44
import Spinner from './Spinner.svelte'
55
export let size: number // px
66
export let icon: Promise<string> | string // svg string or url string
@@ -150,12 +150,12 @@
150150
<div class="placeholder-icon" />
151151
{:then iconLoaded}
152152
<div in:fade class="icon">
153-
{#if isUrl(iconLoaded)}
154-
<!-- load img url -->
155-
<img height="100%" src={iconLoaded} alt="logo" />
156-
{:else}
153+
{#if isSVG(iconLoaded)}
157154
<!-- render svg string -->
158155
{@html iconLoaded}
156+
{:else}
157+
<!-- load img url -->
158+
<img height="100%" src={iconLoaded} alt="logo" />
159159
{/if}
160160
</div>
161161
{/await}

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Collection of React Hooks for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@web3-onboard/common": "^2.0.1",
25-
"@web3-onboard/core": "^2.0.2"
25+
"@web3-onboard/core": "^2.0.3"
2626
},
2727
"peerDependencies": {
2828
"react": "^17.0.2"

0 commit comments

Comments
 (0)