Skip to content

Commit 7d2ce51

Browse files
authored
Cosmos support (#4038)
2 parents fe2ed01 + 0b2c0d7 commit 7d2ce51

File tree

36 files changed

+2174
-44009
lines changed

36 files changed

+2174
-44009
lines changed

app2/src/app.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare global {
2222
// }
2323
}
2424

25-
interface Window extends AptosWindow, KeplrWindow, LeapWindow, Browser, GoogleRecaptcha {
25+
interface Window extends AptosWindow, KeplrWindow, LeapWindow, Browser {
2626
EventEmitter: typeof EventEmitter
2727
}
2828

app2/src/generated/graphql-env.d.ts

Lines changed: 545 additions & 43920 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,125 @@
11
<script lang="ts">
22
import Chain from "$lib/components/Transfer/Chain.svelte"
33
import Card from "$lib/components/ui/Card.svelte"
4-
import { hasFailedExit, isComplete } from "$lib/services/transfer-ucs03-evm"
54
import Button from "$lib/components/ui/Button.svelte"
65
import Assets from "$lib/components/Transfer/Assets.svelte"
76
import Amount from "$lib/components/Transfer/Amount.svelte"
87
import Receiver from "$lib/components/Transfer/Receiver.svelte"
98
import ShowData from "$lib/components/Transfer/ShowData.svelte"
10-
import { transfer } from "$lib/components/Transfer/transfer.svelte.ts"
9+
import { transfer, type TransferStateUnion } from "$lib/components/Transfer/transfer.svelte.ts"
10+
import {
11+
hasFailedExit as hasCosmosFailedExit,
12+
isComplete as isCosmosComplete
13+
} from "$lib/services/transfer-ucs03-cosmos"
14+
import {
15+
hasFailedExit as hasEvmFailedExit,
16+
isComplete as isEvmComplete
17+
} from "$lib/services/transfer-ucs03-evm"
1118
1219
$effect(() => {
1320
transfer.getQuoteToken()
1421
transfer.getWethQuoteToken()
1522
})
16-
</script>
1723
18-
<Card class="max-w-md relative flex flex-col gap-2">
19-
<Chain type="source"/>
20-
<Chain type="destination"/>
21-
<Assets/>
22-
<Amount/>
23-
<Receiver/>
24+
// Simplified status checker using the enum
25+
function getStatus(
26+
state: TransferStateUnion
27+
): "empty" | "filling" | "processing" | "failed" | "complete" {
28+
switch (state._tag) {
29+
case "Empty":
30+
return "empty"
31+
case "EVM": {
32+
if (state.state._tag === "Filling") return "filling"
33+
if (hasEvmFailedExit(state.state)) return "failed"
34+
if (isEvmComplete(state.state)) return "complete"
35+
return "processing"
36+
}
37+
case "Cosmos": {
38+
if (state.state._tag === "Filling") return "filling"
39+
if (hasCosmosFailedExit(state.state)) return "failed"
40+
if (isCosmosComplete(state.state)) return "complete"
41+
return "processing"
42+
}
43+
}
44+
}
45+
46+
function getError(state: TransferStateUnion): string | null {
47+
switch (state._tag) {
48+
case "Empty":
49+
return null
50+
case "EVM":
51+
case "Cosmos": {
52+
const innerState = state.state
53+
if (innerState._tag === "Filling") return null
54+
if (
55+
innerState.state._tag === "Complete" &&
56+
innerState.state.exit._tag === "Failure" &&
57+
"cause" in innerState.state.exit
58+
) {
59+
const cause = innerState.state.exit.cause
60+
return typeof cause === "object" && cause && "cause" in cause
61+
? String(cause.cause)
62+
: String(cause)
63+
}
64+
return null
65+
}
66+
}
67+
}
68+
69+
// Simplified step name extractor
70+
function getStepName(state: TransferStateUnion): string | null {
71+
switch (state._tag) {
72+
case "Empty":
73+
return null
74+
case "EVM":
75+
case "Cosmos":
76+
return state.state._tag
77+
}
78+
}
2479
25-
<!-- For testing -->
26-
<ShowData/>
27-
<!-- For testing -->
80+
let isButtonEnabled = $derived(
81+
getStatus(transfer.state) === "filling" ||
82+
getStatus(transfer.state) === "failed" ||
83+
getStatus(transfer.state) === "complete"
84+
)
2885
86+
let buttonText = $derived(
87+
{
88+
empty: "Select",
89+
filling: "Submit",
90+
processing: "Submitting...",
91+
failed: "Retry",
92+
complete: "Submit"
93+
}[getStatus(transfer.state)]
94+
)
95+
</script>
96+
97+
<Card class="max-w-md relative flex flex-col gap-2">
98+
<Chain type="source" />
99+
<Chain type="destination" />
100+
<Assets />
101+
<Amount />
102+
<Receiver />
103+
<ShowData />
29104
<Button
30105
class="mt-2"
31106
variant="primary"
32107
onclick={transfer.submit}
33-
disabled={transfer.state._tag !== "Filling" && !hasFailedExit(transfer.state) && !isComplete(transfer.state)}
108+
disabled={!isButtonEnabled}
34109
>
35-
{#if transfer.state._tag !== "Filling" && !hasFailedExit(transfer.state) && !isComplete(transfer.state)}
36-
Submitting...
37-
{:else if hasFailedExit(transfer.state)}
38-
Retry
39-
{:else}
40-
Submit
41-
{/if}
110+
{buttonText}
42111
</Button>
43112
</Card>
44-
{JSON.stringify(transfer.state, null, 2)}
113+
114+
{#if transfer.state._tag !== "Empty"}
115+
{#if getStatus(transfer.state) === "filling"}
116+
<div>Select assets and amounts to begin transfer.</div>
117+
{:else if getStatus(transfer.state) === "failed"}
118+
<div style="color: red;">Error: {getError(transfer.state) ?? "Unknown error"}</div>
119+
{:else if getStatus(transfer.state) === "processing"}
120+
<div>Processing {getStepName(transfer.state) ?? "step"}...</div>
121+
{:else if getStatus(transfer.state) === "complete"}
122+
<div style="color: green;">Transfer completed successfully!</div>
123+
{/if}
124+
<pre>{JSON.stringify(transfer.state, null, 2)}</pre>
125+
{/if}

0 commit comments

Comments
 (0)