Skip to content

Commit

Permalink
fix: fixing type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 2, 2024
1 parent 39220a7 commit aae1213
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script lang="ts">
import type { PageData } from './$types';
import * as m from '$lib/paraglide/messages.js';
export let data: PageData;
</script>

<h1>{data.proposer}/{data.name}</h1>
<!--
This section is commented out because the corresponding load method in +page.ts is also commented out.
Once the load method is implemented and returning the expected data, we can uncomment and use this part.
-->

<!-- <h1>{data.proposer}/{data.name}</h1>
<pre>
{JSON.stringify(data.proposal, null, 2)}
</pre>
</pre> -->
4 changes: 1 addition & 3 deletions src/routes/[network]/(explorer)/network/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts">
import * as m from '$lib/paraglide/messages.js';
import Code from '$lib/components/code.svelte';
import { onMount } from 'svelte';
import * as Table from '$lib/components/table';
import { Card, Stack } from '$lib/components/layout';
Expand Down Expand Up @@ -43,7 +41,7 @@
{#each Object.keys(state) as index}
<Table.Row>
<Table.Cell>{index}</Table.Cell>
<Table.Cell>{state[index]}</Table.Cell>
<Table.Cell>{state[index as keyof typeof state]}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import type { PageData } from './$types';
import * as m from '$lib/paraglide/messages.js';
import Code from '$lib/components/code.svelte';
import SendSummary from '$lib/components/summary/eosio.token/transfer.svelte';
Expand All @@ -21,26 +20,55 @@
sellrex: SellREXSummary,
mvfrsavings: MvfrsavingsSummary
}
};
} as const;
export let data: PageData;
import type { SvelteComponent } from 'svelte';
// Define the Action interface
interface Action {
account: string;
name: string;
data: any; // Adjust as necessary
// Other properties if needed
}
// Type guard for account
function isValidAccount(account: string): account is keyof typeof summaryMap {
return account in summaryMap;
}
// Type guard for action name
function isValidActionName(
account: keyof typeof summaryMap,
name: string
): name is keyof (typeof summaryMap)[typeof account] {
return name in summaryMap[account];
}
</script>

{#if data.transaction && data.transaction.trx}
{#each data.transaction.trx.trx.actions as action}
{@const summaryComponent = summaryMap[action.account][action.name]}
{#if summaryComponent}
<svelte:component this={summaryComponent} {action} />
{@const actions = data.transaction.trx.trx.actions as Action[]}
{#each actions as action}
{#if isValidAccount(action.account)}
{@const accountMap = summaryMap[action.account]}
{#if isValidActionName(action.account, action.name)}
{@const summaryComponent = accountMap[action.name]}
<svelte:component this={summaryComponent as typeof SvelteComponent} {action} />
{:else}
<p>Unknown action: {action.account}::{action.name}</p>
{/if}
{:else}
<p>Unknown action: {action.account}::{action.name}</p>
<p>Unknown account: {action.account}</p>
{/if}
<Code>{JSON.stringify(action, null, 2)}</Code>
{/each}
{/if}

{#if data.seq}
{@const trace = data.transaction.traces.find(
(t) => String(t.receipt.global_sequence) === data.seq
(t: { receipt: { global_sequence: number } }) => String(t.receipt.global_sequence) === data.seq
)}
<Code>{JSON.stringify(trace, null, 2)}</Code>
{:else}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import type { PageData } from '../../data/$types';
import * as m from '$lib/paraglide/messages.js';
import type { PageData } from './$types';
export let data: PageData;
</script>
Expand Down

0 comments on commit aae1213

Please sign in to comment.