Skip to content

Commit

Permalink
SellUtils: Fix error « .value of undefined » for estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
mraveux committed Apr 15, 2021
1 parent 21347eb commit 6684568
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/lib/swap/utils/SellUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const { activeSwap: swap } = useSwapsStore();
const { exchangeRates } = useFiatStore();
const { activeCurrency } = useAccountStore();
const { accountBalance: accountBtcBalance, accountUtxos } = useBtcAddressStore();
const { estimate } = useSwapEstimate();

/**
* Sell - Sell crypto related things
Expand All @@ -46,17 +45,21 @@ export const oasisSellLimitExceeded = computed(() => {
return deniedSettlementInfo.detail.reason === DeniedReason.LIMIT_EXCEEDED;
});

export const nimFeePerUnit = computed(() =>
(estimate.value && estimate.value.from.asset === SwapAsset.NIM && estimate.value.from.feePerUnit)
|| (assets.value && assets.value[SwapAsset.NIM].feePerUnit)
|| 0, // Default zero fees for NIM
);
export const nimFeePerUnit = computed(() => {
const { estimate } = useSwapEstimate();

export const btcFeePerUnit = computed(() =>
(estimate.value && estimate.value.from.asset === SwapAsset.BTC && estimate.value.from.feePerUnit)
|| (assets.value && assets.value[SwapAsset.BTC].feePerUnit)
|| 1,
);
return (estimate.value && estimate.value.from.asset === SwapAsset.NIM && estimate.value.from.feePerUnit)
|| (assets.value && assets.value[SwapAsset.NIM].feePerUnit)
|| 0; // Default zero fees for NIM
});

export const btcFeePerUnit = computed(() => {
const { estimate } = useSwapEstimate();

return (estimate.value && estimate.value.from.asset === SwapAsset.BTC && estimate.value.from.feePerUnit)
|| (assets.value && assets.value[SwapAsset.BTC].feePerUnit)
|| 1;
});

// 48 extra weight units for BTC HTLC funding tx
export const btcFeeForSendingAll = computed(() =>
Expand Down Expand Up @@ -118,5 +121,6 @@ export async function updateSellEstimate({ fiatAmount, cryptoAmount }
}
} // eslint-disable-line brace-style

const { estimate } = useSwapEstimate();
estimate.value = newEstimate;
}

0 comments on commit 6684568

Please sign in to comment.