Skip to content

Commit

Permalink
fix: support detecting all offertypes
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Aug 12, 2022
1 parent 618a4e7 commit dd59190
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/components/Earn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -85,10 +88,10 @@ const factorToPercentage = (val, precision = 6) => {
}

const renderOrderType = (val, t) => {
if (val.includes('absoffer')) {
if (isAbsoluteOffer(val)) {
return <rb.Badge bg="info">{t('earn.current.text_offer_type_absolute')}</rb.Badge>
}
if (val.includes('reloffer')) {
if (isRelativeOffer(val)) {
return <rb.Badge bg="primary">{t('earn.current.text_offer_type_relative')}</rb.Badge>
}
return <rb.Badge bg="secondary">{val}</rb.Badge>
Expand All @@ -112,7 +115,7 @@ function CurrentOffer({ offer, nickname }) {
<div className="d-flex flex-column">
<div className={styles.offerLabel}>{t('earn.current.text_cjfee')}</div>
<div>
{offer.ordertype.includes('reloffer') ? (
{isRelativeOffer(offer.ordertype) ? (
<>{factorToPercentage(offer.cjfee)}%</>
) : (
<>
Expand Down
5 changes: 4 additions & 1 deletion src/libs/JmWalletApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd59190

Please sign in to comment.