Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show swap progress #4936

Merged
merged 15 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions frontend/app/src/components/Progress.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

export let percent: number;
export let bg: "button" | "accent" = "button";
export let size = "40px";
</script>

<div class="bar">
<div class="bar" style={`--size: ${size}`}>
<span
class="meter"
class:rtl={$rtlStore}
Expand All @@ -18,15 +19,16 @@
</div>

<style lang="scss">
$progress-bar-x-large: 40px;
$radius: calc(var(--size) / 2);

.bar {
// border: 1px solid rgba(255, 255, 255, 0.2);
border: 1px solid var(--progress-bd);
width: 100%;
height: $progress-bar-x-large;
height: var(--size);
position: relative;
border-radius: math.div($progress-bar-x-large, 2);
// border-radius: math.div($progress-bar-x-large, 2);
border-radius: $radius;
overflow: hidden;
}

Expand Down
86 changes: 86 additions & 0 deletions frontend/app/src/components/ProgressStep.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<script lang="ts">
import { _ } from "svelte-i18n";
import Spinner from "./icons/Spinner.svelte";
import DoneIcon from "svelte-material-icons/CheckCircle.svelte";
import FailedIcon from "svelte-material-icons/CloseCircle.svelte";
import { currentTheme } from "../theme/themes";

export let label: string;
export let status: string;
export let step = 0;
</script>

<div class={`step ${status}`}>
{#if status === "doing"}
<div class="spinner">
<Spinner
size="25px"
foregroundColour={$currentTheme.toast.success.bg}
backgroundColour={"rgba(255,255,255,0.5)"}></Spinner>
<div class="number">{step + 1}</div>
</div>
{:else if status === "overall-done"}
<div class="icon">
<DoneIcon size="30px" viewBox="2 2 24 24" color={$currentTheme.toast.success.bg} />
</div>
{:else if status === "overall-failed"}
<div class="icon">
<FailedIcon size="30px" viewBox="2 2 24 24" color={$currentTheme.error} />
</div>
{:else}
<div class={`index ${status}`}>
{step + 1}
</div>
{/if}
<div class={`label ${status}`}>
{label}
</div>
</div>

<style lang="scss">
.step {
display: flex;
gap: $sp3;
align-items: center;
margin-bottom: $sp4;
&.todo {
color: var(--txt-light);
@include font(book, normal, fs-80);
}
.index {
display: flex;
justify-content: center;
align-items: center;
@include font(book, normal, fs-80);
border: 3px solid red;
width: 25px;
height: 25px;
border-radius: 50%;
&.todo {
border-color: var(--txt-light);
}
&.done {
border-color: var(--toast-success-bg);
}
&.failed {
border-color: var(--error);
}
}
}
.spinner {
position: relative;
height: 25px;
.number {
@include font(book, normal, fs-80);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}

.icon {
width: 25px;
height: 25px;
}
</style>
81 changes: 81 additions & 0 deletions frontend/app/src/components/ProgressSteps.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script lang="ts">
import { _ } from "svelte-i18n";
import { fade } from "svelte/transition";
import { flip } from "svelte/animate";
import Progress from "./Progress.svelte";
import ProgressStep from "./ProgressStep.svelte";
import type { InterpolationValues } from "openchat-client";

export let stepLabels: string[];
export let labelValues: InterpolationValues | undefined = undefined;
export let step = 0;
export let finalLabel: string | undefined;

type Status = "done" | "doing" | "todo" | "failed";

let steps: Status[] = Array.from(Array(stepLabels.length)).map((_, index) =>
index === 0 ? "doing" : "todo",
);

let finalStatus: "overall-done" | "overall-failed" | undefined = undefined;

$: [toShow, _stop] = steps.reduce<[Status[], boolean]>(
([all, stop], s) => {
if (stop) return [all, stop];
if (s === "todo") return [all, true];
all.push(s);
return [all, false];
},
[[], false] as [Status[], boolean],
);

$: percent = (step / steps.length) * 100;

export function next(previousSuccess: boolean, outcome?: boolean) {
step++;

const [status, _] = steps.reduce<[Status[], boolean]>(
([all, skip], status) => {
if (!skip) {
if (status === "doing") {
status = previousSuccess ? "done" : "failed";
if (outcome !== undefined) {
skip = true;
}
}
if (status === "todo") {
status = "doing";
skip = true;
}
}
all.push(status);
return [all, skip];
},
[[], false] as [Status[], boolean],
);
steps = status;

if (outcome !== undefined) {
finalStatus = outcome ? "overall-done" : "overall-failed";
}
}
</script>

<div>
{#each toShow as status, i (stepLabels[i])}
<div in:fade={{ duration: 500 }} animate:flip={{ duration: 500 }}>
<ProgressStep label={$_(stepLabels[i], { values: labelValues })} step={i} {status} />
</div>
{/each}
{#if finalStatus !== undefined && finalLabel !== undefined}
<div>
<ProgressStep label={$_(finalLabel, { values: labelValues })} status={finalStatus} />
</div>
{/if}
</div>

{#if finalStatus === undefined}
<div class="progress">
<Progress size={"30px"} {percent} />
</div>
{/if}
9 changes: 6 additions & 3 deletions frontend/app/src/components/home/BalanceWithRefresh.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
export let bold = false;
export let toppingUp = false;
export let showTopUp = false;
export let showRefresh = true;
export let refreshing = false;

$: cryptoLookup = client.cryptoLookup;
Expand Down Expand Up @@ -58,9 +59,11 @@
<div class="amount" class:bold>
{client.formatTokens(value, minDecimals, tokenDetails.decimals)}
</div>
<div class="refresh" class:refreshing on:click={refresh}>
<Refresh size={"1em"} color={"var(--icon-txt)"} />
</div>
{#if showRefresh}
<div class="refresh" class:refreshing on:click={refresh}>
<Refresh size={"1em"} color={"var(--icon-txt)"} />
</div>
{/if}
{#if showTopUp}
<div class="top-up" on:click={topUp} title={$_("cryptoAccount.topUp")}>
<Plus size={"1em"} color={toppingUp ? "var(--icon-selected)" : "var(--icon-txt)"} />
Expand Down
Loading
Loading