Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
samuveth committed Oct 14, 2023
1 parent 51501a1 commit 29cfb50
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/components/BaseMarkdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Remarkable } from 'remarkable';
import { linkify } from 'remarkable/linkify';
// import sanitizeHtml from 'sanitize-html';
import { getIpfsUrl } from '@/helpers/utils';
import { isSnapshotUrl } from '@/helpers/utils';
const props = defineProps<{
body: string;
Expand Down Expand Up @@ -34,7 +35,11 @@ const markdown = computed(() => {
function handleLinkClick(e, url) {
e.preventDefault();
clickedUrl.value = url;
if (url.includes('snapshot.org/#/')) return handleConfirm();
if (isSnapshotUrl(url)) {
return handleConfirm();
}
showModal.value = true;
}
Expand Down
11 changes: 2 additions & 9 deletions src/components/TextAutolinker.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import Autolinker from 'autolinker';
import { isSnapshotUrl } from '@/helpers/utils';
interface Props {
text: string;
Expand All @@ -24,15 +25,7 @@ function handleLinkClick(e, url) {
e.preventDefault();
clickedUrl.value = url;
let parsedUrl;
try {
parsedUrl = new URL(url);
} catch (err) {
console.error('Invalid URL', err);
return;
}
if (parsedUrl.hostname === 'snapshot.org') {
if (isSnapshotUrl(url)) {
return handleConfirm();
}
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,19 @@ export async function resolveLens(handle: string) {
return null;
}
}

export function isSnapshotUrl(url: string) {
let parsedUrl;
try {
parsedUrl = new URL(url);
} catch (err) {
console.error('Invalid URL', err);
return;
}

if (parsedUrl.hostname === 'snapshot.org') {
return true;
}

return false;
}

0 comments on commit 29cfb50

Please sign in to comment.