diff --git a/packages/desktop/electron/main.js b/packages/desktop/electron/main.js index 6b315a907df..ab503e91509 100644 --- a/packages/desktop/electron/main.js +++ b/packages/desktop/electron/main.js @@ -191,6 +191,7 @@ function isUrlAllowed(targetUrl) { 'wiki.iota.org', 'explorer.iota.org', 'iotatreasury.org', + 'govern.iota.org', // Assembly / Shimmer 'assembly.sc', diff --git a/packages/shared/lib/helpers.ts b/packages/shared/lib/helpers.ts index 177be3543e0..4d881cebbc2 100644 --- a/packages/shared/lib/helpers.ts +++ b/packages/shared/lib/helpers.ts @@ -269,3 +269,18 @@ export const isBright = (color: string): boolean => { } } } + +/** + * Parse plain text and add html tags to every link found + * @param plainText The text to be parsed + * @param classes the classes to add to the tag + * @returns The input plain text with tags added + */ +export function addLinkHtmlTagsToPlainText(plainText: string, classes: string = ''): string { + if (!plainText) { + return + } else { + const regex = /((http|https)?:\/\/[^\s]+)/g + return plainText.replace(regex, (url) => `${url}`) + } +} diff --git a/packages/shared/routes/dashboard/governance/views/GovernanceEventInfo.svelte b/packages/shared/routes/dashboard/governance/views/GovernanceEventInfo.svelte index 2e139121aa3..54d77709a33 100644 --- a/packages/shared/routes/dashboard/governance/views/GovernanceEventInfo.svelte +++ b/packages/shared/routes/dashboard/governance/views/GovernanceEventInfo.svelte @@ -16,6 +16,7 @@ import { formatUnitBestMatch } from '@lib/units' import { selectedAccountStore } from '@lib/wallet' import { DashboardPane, GovernanceInfoTooltip, Icon, Spinner, Text, Tooltip } from 'shared/components' + import { addLinkHtmlTagsToPlainText } from 'shared/lib/helpers' import { showAppNotification } from 'shared/lib/notifications' import { isChangingParticipation, @@ -23,7 +24,9 @@ pendingParticipations, } from 'shared/lib/participation/stores' import { ParticipationAction } from 'shared/lib/participation/types' + import { Platform } from 'shared/lib/platform' import { isSyncing } from 'shared/lib/wallet' + import { onMount } from 'svelte' export let event: ParticipationEvent export let nextVote: VotingEventAnswer = null @@ -41,6 +44,15 @@ $: disableVoting = $isChangingParticipation || $pendingParticipations?.length > 0 || !!$participationAction || $isSyncing + $: eventAdditionalInfo = addLinkHtmlTagsToPlainText( + event?.information?.additionalInfo, + 'cursor-pointer text-blue-500' + ) + $: eventQuestionsInfo = addLinkHtmlTagsToPlainText( + event?.information?.payload?.questions[0]?.text, + 'cursor-pointer text-blue-500' + ) + let disableVotingMessages: { show?: boolean busy?: boolean @@ -175,6 +187,28 @@ disableVotingMessages = disableVotingMessages } } + + // We need to add event listeners to all links from plain text to make them work + onMount(() => { + const linksFromPlainText = document.querySelectorAll('.link-from-plaintext') + const onLinkClick = (e: MouseEvent) => { + e.preventDefault() + const href = (e.target as HTMLElement).getAttribute('href') + if (href) { + Platform.openUrl(href) + } + } + linksFromPlainText?.forEach((link) => { + link.addEventListener('click', (e) => { + e.preventDefault() + const href = link.getAttribute('href') + if (href) { + window.open(href, '_blank') + } + }) + }) + return () => linksFromPlainText?.forEach((link) => link.removeEventListener('click', onLinkClick)) + }) @@ -206,14 +240,14 @@
{event?.information?.name} - {#if event?.information?.payload?.questions[0]?.text} + {#if eventAdditionalInfo} - {event?.information?.additionalInfo} + {@html eventAdditionalInfo} {/if} - {#if event?.information?.additionalInfo} + {#if eventQuestionsInfo} - {event?.information?.payload?.questions[0]?.text} + {@html eventQuestionsInfo} {/if}
diff --git a/packages/shared/routes/dashboard/governance/views/GovernanceEvents.svelte b/packages/shared/routes/dashboard/governance/views/GovernanceEvents.svelte index 21980d4d6c2..e12fc700b31 100644 --- a/packages/shared/routes/dashboard/governance/views/GovernanceEvents.svelte +++ b/packages/shared/routes/dashboard/governance/views/GovernanceEvents.svelte @@ -34,7 +34,7 @@ {#if event} -
+
{event?.information?.name} - +