-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I see it correctly then you had to make bitcoinWallet
and ethereumWallet
optional and expose these two fields publicly just to facilitate the tests.
I think we should try to avoid this.
We won't need a Bitcoin Wallet if ones only wants to do LNBTC-ERC20 swaps. Hence I believe it is a move in the right direction. |
Ok, valid point. |
const comitClient = new ComitClient(bitcoinWallet, ethereumWallet, cnd); | ||
const comitClient = new ComitClient(cnd); | ||
comitClient.ethereumWallet = ethereumWallet; | ||
comitClient.bitcoinWallet = bitcoinWallet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing these fields publicly you could apply the builder pattern. This would allow for something like this:
const comitClient = new ComitClient(cnd)
.withEthereumWallet(ethereumWallet)
.withBitcoinWallet(bitcoinWallet)
....;
Let me know what you think and I can provide a small PR once your changes are in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please hold, I am finishing off few things. I'll ping you.
import { getToken, Token } from "../tokens/tokens"; | ||
|
||
export interface Order { | ||
tradingPair: string; | ||
export interface OrderParams { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 I find the design of the Order
a bit confusing. From code
export class Order {
constructor(
public readonly orderParams: OrderParams,
public readonly criteria: TakerCriteria,
public readonly takeOrder: (
orderParams: OrderParams
) => Promise<Swap | undefined>
) {}
So the order consists of OrderParams
and a TakerCriteria
, why is the abstraction of OrderParams
needed? What exactly is a TakerCriteria
?
I feel there is quite a lot of classes now and it's not immediately understandable why and what they are for.
Motivation for writing this: Started to write comments for code documentation and it's not that easy to explain what is going on. What is currently there works, but I wonder if we could design it so it is easier to understand.
Can we simplify this by integrating the OrderParams
into the Order
? Is this abstraction really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that the lib consumer is not supposed to constructor Order
by themselves.
They would only use OrderParams
(a simple object) to add orders to the order book.
Interesting point about documentation because this means that the constructor of Order
should not be documented for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand what you are doing, but I still find the naming a bit confusing. I don't have a perfect solution in mind yet, but maybe we should step back, take a whiteboard and design this outside the code. The way Order
and OrderParams
is introduced in this PR is a bit confusing for me. we have a lot of variables named order
now, that are actually OrderParams
. Maybe a simple rename can fix this, not sure.
src/negotiation/maker_client.ts
Outdated
return response.data; | ||
} | ||
|
||
public async takeOrder(order: OrderParams, swapId: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ How come we already have a swapId
at this point? Aren't we supposed to get the swapId
from the maker after taking the order?
(Maybe I'm just confused by the syntax...?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the swap Id indeed. I have documented in f622aea
Overall: Like the approach towards tests, but don't understand why certain design decisions were made. Would be cool if could go over this with me Franck and explain it (Would help for creating good documentation). |
Please review @da-kami I added documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sry for being a bit nit-picky about this @D4nte - added some comments.
584e472
to
ec07812
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added one commit.
*/ | ||
export class Order { | ||
/** | ||
* **Note: This should not be used, `Order` should be created by using `TakerNegotiatior.getOrder()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Note: This should not be used, `Order` should be created by using `TakerNegotiatior.getOrder()` |
Not a blocker, feel free to ignore.
Not only this helps with mocking but I believe it is the correct move. Indeed, if one decides to use the SDK for LN-Bitcoin to ERC20 only, then It would not use a `BitcoinWallet` class but one that handles LightningBitcoin
Create mock class to mock axios calls.
dd03f68
to
2077cd3
Compare
440: Use new `TakerNegotiator` interface r=D4nte a=D4nte Incorporates SDK changes from comit-network/comit-js-sdk#116 Related to comit-network/comit-js-sdk#89 Co-authored-by: Franck Royer <franck@coblox.tech>
bors r+ |
Already running a review |
This test demonstrates how to use the
TakerNegotiator
.Note that the last part
await order.take()
is not tested as it involves creating a few mock. Not yet sure whether I should do it.comit-js-sdk/src/negotiation/taker_negotiator.spec.ts
Line 25 in f6d5cf0
Usage in the example drafted here: comit-network/create-comit-app#440
Resolves #89