-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract cell components from TokensTableRow (#4909)
# Motivation We want to try to reuse the tokens table structure and style for the neurons table. The `TokensTable` component is currently very specific to the tokens table. By extracting tokens specific subcomponents, I'm hoping to separate the generic table structure from the tokens specific rendering. And this should make it easier to subsequently create a generic table component and use that for both the tokens table and the neurons table. # Changes 1. Create `TokenTitleCell`, `TokenBalanceCell` and `TokenActionsCell` component. 2. Use those components in `TokensTableRow.svelte` # Tests All tokens table functionality continues to be covered by `src/tests/lib/components/tokens/TokensTable.spec.ts`. # Todos - [ ] Add entry to changelog (if necessary). not necessary
- Loading branch information
Showing
4 changed files
with
110 additions
and
84 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<script lang="ts"> | ||
import GoToDetailIcon from "./actions/GoToDetailIcon.svelte"; | ||
import ReceiveButton from "./actions/ReceiveButton.svelte"; | ||
import SendButton from "./actions/SendButton.svelte"; | ||
import { | ||
UserTokenAction, | ||
type UserTokenData, | ||
type UserTokenLoading, | ||
} from "$lib/types/tokens-page"; | ||
import { isUserTokenData } from "$lib/utils/user-token.utils"; | ||
import { nonNullish } from "@dfinity/utils"; | ||
import type { SvelteComponent, ComponentType } from "svelte"; | ||
export let userTokenData: UserTokenData | UserTokenLoading; | ||
const actionMapper: Record< | ||
UserTokenAction, | ||
ComponentType<SvelteComponent<{ userToken: UserTokenData }>> | ||
> = { | ||
[UserTokenAction.GoToDetail]: GoToDetailIcon, | ||
[UserTokenAction.Receive]: ReceiveButton, | ||
[UserTokenAction.Send]: SendButton, | ||
}; | ||
let userToken: UserTokenData | undefined; | ||
$: userToken = isUserTokenData(userTokenData) ? userTokenData : undefined; | ||
</script> | ||
|
||
{#if nonNullish(userToken)} | ||
{#each userToken.actions as action} | ||
<svelte:component this={actionMapper[action]} {userToken} on:nnsAction /> | ||
{/each} | ||
{/if} |
27 changes: 27 additions & 0 deletions
27
frontend/src/lib/components/tokens/TokensTable/TokenBalanceCell.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import type { UserTokenData, UserTokenLoading } from "$lib/types/tokens-page"; | ||
import AmountDisplay from "$lib/components/ic/AmountDisplay.svelte"; | ||
import { Spinner } from "@dfinity/gix-components"; | ||
import { UnavailableTokenAmount } from "$lib/utils/token.utils"; | ||
export let userTokenData: UserTokenData | UserTokenLoading; | ||
</script> | ||
|
||
{#if userTokenData.balance instanceof UnavailableTokenAmount} | ||
<span data-tid="token-value-label" | ||
>{`-/- ${userTokenData.balance.token.symbol}`}</span | ||
> | ||
{:else if userTokenData.balance === "loading"} | ||
<span data-tid="token-value-label" class="balance-spinner" | ||
><Spinner inline size="tiny" /></span | ||
> | ||
{:else} | ||
<AmountDisplay singleLine amount={userTokenData.balance} /> | ||
{/if} | ||
|
||
<style lang="scss"> | ||
.balance-spinner { | ||
display: flex; | ||
align-items: center; | ||
} | ||
</style> |
42 changes: 42 additions & 0 deletions
42
frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script lang="ts"> | ||
import type { UserTokenData, UserTokenLoading } from "$lib/types/tokens-page"; | ||
import Logo from "../../ui/Logo.svelte"; | ||
import { nonNullish } from "@dfinity/utils"; | ||
export let userTokenData: UserTokenData | UserTokenLoading; | ||
</script> | ||
|
||
<div class="title-logo-wrapper"> | ||
<Logo | ||
src={userTokenData.logo} | ||
alt={userTokenData.title} | ||
size="medium" | ||
framed | ||
/> | ||
<div class="title-wrapper"> | ||
<h5 data-tid="project-name">{userTokenData.title}</h5> | ||
{#if nonNullish(userTokenData.subtitle)} | ||
<span data-tid="project-subtitle" class="description" | ||
>{userTokenData.subtitle}</span | ||
> | ||
{/if} | ||
</div> | ||
</div> | ||
|
||
<style lang="scss"> | ||
h5 { | ||
margin: 0; | ||
} | ||
.title-logo-wrapper { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--padding); | ||
.title-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--padding-0_5x); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters