Skip to content

Commit 64d943d

Browse files
committed
fix(app2): allow no fee
Signed-off-by: Eric Hegnes <eric@hegnes.com>
1 parent 6de3022 commit 64d943d

File tree

5 files changed

+63
-49
lines changed

5 files changed

+63
-49
lines changed

app2/src/lib/stores/fee.svelte.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,32 @@ const createFeeStore = () => {
166166
const baseFees: O.Option<BaseFees> = $derived(pipe(
167167
TransferData.channel,
168168
O.map(Struct.get("fees")),
169-
O.map(Struct.omit("PACKET_SEND_LC_UPDATE_L2")),
170169
O.map((fees) => {
171-
const withDefault = O.getOrElse<GasFee>(() => GasFee.make(BigDecimal.make(0n, 0)))<GasFee>
172-
return Struct.evolve(fees, {
173-
PACKET_RECV: withDefault,
174-
PACKET_SEND_LC_UPDATE_L0: withDefault,
175-
PACKET_SEND_LC_UPDATE_L1: withDefault,
176-
})
170+
// const withDefault = O.getOrElse<GasFee>(() => GasFee.make(BigDecimal.make(0n, 0)))<GasFee>
171+
const withDefault = (x: O.Option<BigDecimal.BigDecimal>): GasFee => {
172+
if (O.isSome(x)) {
173+
console.log("IS SOME", JSON.stringify(x))
174+
return GasFee.make(x.value)
175+
} else {
176+
console.log("IS NONE", JSON.stringify(x))
177+
return GasFee.make(BigDecimal.make(0n, 0))
178+
}
179+
}
180+
console.log("BEFORE EVOLUTION")
181+
const result = {
182+
PACKET_RECV: withDefault(fees.PACKET_RECV),
183+
PACKET_SEND_LC_UPDATE_L0: withDefault(fees.PACKET_SEND_LC_UPDATE_L0),
184+
PACKET_SEND_LC_UPDATE_L1: withDefault(fees.PACKET_SEND_LC_UPDATE_L1),
185+
} as const
186+
console.log("AFTER EVOLUTION")
187+
188+
return result
189+
190+
// return Struct.evolve(fees, {
191+
// PACKET_RECV: withDefault,
192+
// PACKET_SEND_LC_UPDATE_L0: withDefault,
193+
// PACKET_SEND_LC_UPDATE_L1: withDefault,
194+
// })
177195
}),
178196
))
179197

@@ -618,36 +636,28 @@ const createFeeStore = () => {
618636
// ucs03address: string
619637
// }
620638

621-
const feeIntent: E.Either<FeeIntent, string> = $derived(E.gen(function*() {
622-
const _totalFee = yield* pipe(
623-
totalFee,
624-
E.fromOption(() => "No total fee"),
625-
)
626-
const sourceChain = yield* pipe(
627-
TransferData.sourceChain,
628-
E.fromOption(() => "No source chain"),
629-
)
630-
const gasDenom = yield* pipe(
631-
R.get(GAS_DENOMS, sourceChain.universal_chain_id),
632-
E.fromOption(() => `No gas denom for ${sourceChain.universal_chain_id}`),
633-
)
639+
const intent: O.Option<E.Either<FeeIntent, string>> = $derived(O.gen(function*() {
640+
const _totalFee = yield* totalFee
641+
const sourceChain = yield* TransferData.sourceChain
634642

635-
const baseToken = gasDenom.address
636-
// TODO: get from more reliable source
637-
const decimals = gasDenom.decimals
638-
const baseAmount = BigDecimal.round(_totalFee, { scale: gasDenom.decimals })
639-
640-
return {
641-
decimals,
642-
baseToken,
643-
quoteAmount: TokenRawAmount.make(0n),
644-
baseAmount: TokenRawAmount.make(baseAmount.value),
645-
} as const
643+
return E.gen(function*() {
644+
const { decimals, address: baseToken } = yield* pipe(
645+
R.get(GAS_DENOMS, sourceChain.universal_chain_id),
646+
E.fromOption(() => `No gas denom for ${sourceChain.universal_chain_id}`),
647+
)
648+
const baseAmount = BigDecimal.round(_totalFee, { scale: decimals })
649+
return {
650+
decimals,
651+
baseToken,
652+
quoteAmount: TokenRawAmount.make(0n),
653+
baseAmount: TokenRawAmount.make(baseAmount.value),
654+
} as const
655+
})
646656
}))
647657

648658
return {
649-
get feeIntent() {
650-
return feeIntent
659+
get intent() {
660+
return intent
651661
},
652662
get baseFees() {
653663
return baseFees

app2/src/lib/transfer/normal/index.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,10 @@ $effect(() => {
134134
let context: TransferContext | null = null
135135
136136
while (true) {
137-
const feeIntent = Option.getRight(FeeStore.feeIntent)
138-
139137
const result: StateResult | void = yield* createContextState(
140138
currentState,
141139
transferData,
142-
feeIntent,
140+
FeeStore.intent,
143141
)
144142
145143
if (!result) {

app2/src/lib/transfer/normal/services/filling.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
type TransferContext,
1818
} from "$lib/transfer/shared/services/filling/create-context.ts"
1919
import { createOrdersBatch } from "$lib/transfer/shared/services/filling/create-orders.ts"
20-
import { Data, Effect, Match, Option } from "effect"
20+
import { Data, Effect, Either as E, Match, Option } from "effect"
2121
import { pipe } from "effect/Function"
2222

2323
export type StateResult = {
@@ -85,7 +85,7 @@ const complete = (msg: string, context: TransferContext): StateResult => ({
8585
export const createContextState = (
8686
cts: CreateContextState,
8787
transfer: TransferData,
88-
fee: Option.Option<FeeIntent>,
88+
fee: Option.Option<E.Either<FeeIntent, string>>,
8989
) => {
9090
return CreateContextState.$match(cts, {
9191
Empty: () => Effect.void,
@@ -104,7 +104,7 @@ export const createContextState = (
104104
EmptyAmount: () => Effect.succeed(ok(Empty(), "Enter amount")),
105105
InvalidAmount: () => Effect.succeed(ok(Empty(), "Invalid amount")),
106106
ReceiverMissing: () => Effect.succeed(ok(Empty(), "Select receiver")),
107-
NoFee: () => Effect.succeed(ok(Empty(), "No fee")),
107+
NoFee: ({ message }) => Effect.succeed(ok(Empty(), message ?? "Loading fee...")),
108108
Ready: (args) => Effect.succeed(ok(Validation({ args }), "Validating...")),
109109
})
110110
},

app2/src/lib/transfer/shared/components/FeeDetails.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const feeConfig = O.none()
171171
</div>
172172

173173
<!-- TODO: Receipt transparency -->
174+
<!--
174175
<div class="border-t border-zinc-800 px-4 py-3">
175176
<div class="flex items-center justify-between text-xs mb-3">
176177
<span class="text-zinc-400 font-medium">Route</span>

app2/src/lib/transfer/shared/services/filling/check-filling.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { wallets } from "$lib/stores/wallets.svelte.ts"
33
import type { TransferData } from "$lib/transfer/shared/data/transfer-data.svelte.ts"
44
import { signingMode } from "$lib/transfer/signingMode.svelte.ts"
55
import type { AddressCanonicalBytes, Chain, Channel, ChannelId } from "@unionlabs/sdk/schema"
6-
import { Data, Option } from "effect"
6+
import { Data, Either as E, Option } from "effect"
77

88
export interface TransferArgs {
99
sourceChain: Chain
@@ -34,15 +34,17 @@ export type FillingState = Data.TaggedEnum<{
3434
ReceiverMissing: {}
3535
NoRoute: {}
3636
NoContract: {}
37-
NoFee: {}
37+
NoFee: {
38+
message?: string | undefined
39+
}
3840
Ready: TransferArgs
3941
}>
4042

4143
export const FillingState = Data.taggedEnum<FillingState>()
4244

4345
export const getFillingState = (
4446
transferData: TransferData,
45-
fee: Option.Option<FeeIntent>,
47+
fee: Option.Option<E.Either<FeeIntent, string>>,
4648
): FillingState => {
4749
if (!wallets.hasAnyWallet() && signingMode.mode === "single") {
4850
return FillingState.NoWallet()
@@ -90,12 +92,16 @@ export const getFillingState = (
9092
return FillingState.ReceiverMissing()
9193
}
9294

93-
if (
94-
Option.isNone(fee)
95-
) {
96-
return FillingState.NoFee()
95+
if (Option.isNone(fee)) {
96+
return FillingState.NoFee({})
9797
}
9898

99+
if (E.isLeft(fee.value)) {
100+
return FillingState.NoFee({ message: fee.value.left })
101+
}
102+
103+
const unwrappedFee = fee.value.right
104+
99105
// TODO: if fee is Some<Either.Left<Error>> => error state
100106

101107
const unwrapped = Option.all({
@@ -105,7 +111,6 @@ export const getFillingState = (
105111
parsedAmount: transferData.parsedAmount,
106112
baseToken: transferData.baseToken,
107113
ucs03address: transferData.ucs03address,
108-
fee,
109114
})
110115

111116
return Option.match(unwrapped, {
@@ -115,7 +120,7 @@ export const getFillingState = (
115120
},
116121

117122
onSome: (
118-
{ destinationChain, channel, receiver, parsedAmount, baseToken, ucs03address, fee },
123+
{ destinationChain, channel, receiver, parsedAmount, baseToken, ucs03address },
119124
) =>
120125
FillingState.Ready({
121126
sourceChain,
@@ -131,7 +136,7 @@ export const getFillingState = (
131136
sourceRpcType: sourceChain.rpc_type,
132137
destinationRpcType: destinationChain.rpc_type,
133138
sourceChannelId: channel.source_channel_id,
134-
fee,
139+
fee: unwrappedFee,
135140
}),
136141
})
137142
},

0 commit comments

Comments
 (0)