Skip to content

Commit

Permalink
Add signatories list dialog (#421)
Browse files Browse the repository at this point in the history
* Add signatories list dialog

* Address PR comments and commit suggestions

* Fix error handling for curator proxy address

* Minor fixes

* Linting

* Improve logging

---------

Co-authored-by: BlertaGalani <[email protected]>
  • Loading branch information
BlertaSunCacti and BlertaGalani authored Jan 18, 2025
1 parent 1e95230 commit f301dee
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/components/curator-actions/BountyCardDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import CopyableAddress from '../common/CopyableAddress.svelte';
import { formatDate } from '../../utils/common';
import { formatPlanckToDot } from '../../utils/polkadot';
import Signatories from './Signatories.svelte';
export let bounty: Bounty;
export let description: string | undefined;
export let remainingBalance: string | undefined;
let detailsExpanded = false;
let curatorsDialogOpen = false;
function handleMoreDetailsToggleClick() {
detailsExpanded = !detailsExpanded;
Expand All @@ -20,7 +22,7 @@

<div class="bg-curatorCarousel xl:pt-6 text-white w-full p-0 sm:p-3">
<!-- Desktop design -->
<div class="hidden lg:flex lg:flex-col gap-3 justify-start lg:ml-7">
<div class="hidden lg:flex lg:flex-col gap-3 lg:ml-7">
<section class="flex flex-col lg:flex lg:flex-row lg:justify-between">
<section class="flex flex-col lg:flex-row">
{#if remainingBalance}
Expand Down Expand Up @@ -63,15 +65,18 @@
<p>{formatDate(bounty.expiryDate)}</p>
</section>
{/if}
{#if bounty.curator}
<div class="mt-4 lg:mt-0">
<p class="text-xs">Curator</p>
<CopyableAddress address={bounty.curator} />
</div>
{/if}
</div>
<!-- -->
</section>
{#if bounty.curator}
<button
class="flex justify-end lg:mr-12 2xl:mr-44 text-accent bg-white font-bold rounded-md lg:h-auto lg:pt-1 lg:max-w-32"
on:click={() => {
curatorsDialogOpen = true;
}}
>
SHOW CURATORS
</button>
{/if}
</section>
</div>

Expand Down Expand Up @@ -118,12 +123,7 @@
<p class="text-xs">Curator Fee</p>
<p class="text-md"><span>{formatPlanckToDot(bounty.fee)}</span> DOT</p>
</div>
{#if bounty.curator}
<div class="space-y-1">
<p class="text-xs">Curator</p>
<CopyableAddress address={bounty.curator} />
</div>
{/if}

{#if description}
<section class="text-xs space-y-1">
<BountyDescription description={DOMPurify.sanitize(description)} />
Expand All @@ -137,6 +137,16 @@
</section>
{/if}
</div>
{#if bounty.curator}
<button
class="w-full h-12 button-popup font-bold rounded-md"
on:click={() => {
curatorsDialogOpen = true;
}}
>
SHOW CURATORS
</button>
{/if}
<div class="flex justify-center items-center">
<ExternalLinks dimension={10} bountyId={bounty.id} />
</div>
Expand All @@ -157,3 +167,5 @@
{/if}
</div>
</div>

<Signatories bind:open={curatorsDialogOpen} {bounty} curatorAddress={bounty.curator} />
46 changes: 46 additions & 0 deletions src/components/curator-actions/Signatories.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script lang="ts">
import { onMount } from 'svelte';
import type { Bounty } from '../../types/bounty';
import { fetchMultisigSignatories } from './fetch-signatories';
import CopyableAddress from '../common/CopyableAddress.svelte';
import Dialog from '../common/Dialog.svelte';
export let open = false;
export let bounty: Bounty;
export let curatorAddress = '';
let signatories: string[] | undefined;
onMount(async () => {
if (curatorAddress) {
signatories = await fetchMultisigSignatories(curatorAddress);
} else {
signatories = [];
}
});
</script>

<Dialog bind:open title="CURATORS LIST">
<div class="modal mt-5">
<div class="space-y-3">
<div class="space-y-1">
<p class="font-bold">Curator Proxy:</p>
<p><CopyableAddress address={bounty.curator} /></p>
</div>
<section class="space-y-1">
<p class="font-bold">Signatories:</p>
{#if signatories === undefined}
<p>Loading...</p>
{:else if signatories.length > 0}
<ul>
{#each signatories as address}
<li><CopyableAddress {address} /></li>
{/each}
</ul>
{:else}
<p>No signatories found.</p>
{/if}
</section>
</div>
</div>
</Dialog>
51 changes: 51 additions & 0 deletions src/components/curator-actions/fetch-signatories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { get } from 'svelte/store';
import { dotApi } from '../../stores';

async function fetchCuratorProxyAddress(accountId: string) {
const api = get(dotApi);
const proxy = await api.query.Proxy.Proxies.getValue(accountId);

return proxy[0][0].delegate;
}

type GraphQLResponse = {
data: {
multisigAddress: {
signatories: string[];
} | null;
};
};

export async function fetchMultisigSignatories(curatorAddress: string): Promise<string[]> {
const graphqlEndpoint = 'https://dot-gh-api.statescan.io/graphql';

try {
const proxyAddress = await fetchCuratorProxyAddress(curatorAddress);

const query = `
query {
multisigAddress(account: "${proxyAddress}") {
signatories
}
}`;

const response = await fetch(graphqlEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ query })
});

if (!response.ok) {
throw new Error('Error fetching signatories');
}

const data = (await response.json()) as GraphQLResponse;

return data.data.multisigAddress?.signatories || [];
} catch (error) {
console.error('Error fetching signatories', error);
return [];
}
}

0 comments on commit f301dee

Please sign in to comment.