From dd591901eace3d5e6aa5dde7fbb78e832e52ddbe Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Fri, 12 Aug 2022 13:40:43 +0200 Subject: [PATCH] fix: support detecting all offertypes --- src/components/Earn.jsx | 13 ++++++++----- src/libs/JmWalletApi.ts | 5 ++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/Earn.jsx b/src/components/Earn.jsx index 90812a43e..4d249cca4 100644 --- a/src/components/Earn.jsx +++ b/src/components/Earn.jsx @@ -29,8 +29,11 @@ const RELOAD_FIDELITY_BONDS_DELAY_MS = 2_000 const OFFERTYPE_REL = 'sw0reloffer' const OFFERTYPE_ABS = 'sw0absoffer' -const isRelativeOffer = (offertype) => offertype === OFFERTYPE_REL -const isAbsoluteOffer = (offertype) => offertype === OFFERTYPE_ABS +// can be any of ['sw0reloffer', 'swreloffer', 'reloffer'] +const isRelativeOffer = (offertype) => offertype.includes('reloffer') + +// can be any of ['sw0absoffer', 'swabsoffer', 'absoffer'] +const isAbsoluteOffer = (offertype) => offertype.includes('absoffer') const FORM_INPUT_LOCAL_STORAGE_KEYS = { offertype: 'jm-offertype', @@ -85,10 +88,10 @@ const factorToPercentage = (val, precision = 6) => { } const renderOrderType = (val, t) => { - if (val.includes('absoffer')) { + if (isAbsoluteOffer(val)) { return {t('earn.current.text_offer_type_absolute')} } - if (val.includes('reloffer')) { + if (isRelativeOffer(val)) { return {t('earn.current.text_offer_type_relative')} } return {val} @@ -112,7 +115,7 @@ function CurrentOffer({ offer, nickname }) {
{t('earn.current.text_cjfee')}
- {offer.ordertype.includes('reloffer') ? ( + {isRelativeOffer(offer.ordertype) ? ( <>{factorToPercentage(offer.cjfee)}% ) : ( <> diff --git a/src/libs/JmWalletApi.ts b/src/libs/JmWalletApi.ts index dd5871090..fe2f9ca78 100644 --- a/src/libs/JmWalletApi.ts +++ b/src/libs/JmWalletApi.ts @@ -64,7 +64,10 @@ interface WalletUnlockRequest { password: string } -type OrderType = 'sw0reloffer' | 'sw0absoffer' +// only support starting the maker with native segwit offers +type RelOfferType = 'sw0reloffer' +type AbsOfferType = 'sw0absoffer' +type OrderType = RelOfferType | AbsOfferType interface StartMakerRequest { cjfee_a: AmountSats