Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: percentage of backed offers in finance #924

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/components/detail/DetailWidget/DetailWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CommitButton,
exchanges,
extractUserFriendlyError,
offers,
Provider,
subgraph
Expand All @@ -18,6 +19,7 @@ import {
constants,
ContractTransaction,
ethers,
providers,
utils
} from "ethers";
import {
Expand Down Expand Up @@ -804,7 +806,10 @@ const DetailWidget: React.FC<IDetailWidget> = ({
setCommitType(null);
removePendingTransaction("offerId", offer.id);
};
const onCommitError = (error: Error) => {
const onCommitError = async (
error: Error,
{ txResponse }: { txResponse: providers.TransactionResponse | undefined }
) => {
console.error("onError", error);
setIsLoading(false);
const hasUserRejectedTx = getHasUserRejectedTx(error);
Expand All @@ -814,7 +819,10 @@ const DetailWidget: React.FC<IDetailWidget> = ({
Sentry.captureException(error);
showModal(modalTypes.DETAIL_WIDGET, {
title: "An error occurred",
message: error.message,
message: await extractUserFriendlyError(error, {
txResponse,
provider: signer?.provider
}),
type: "ERROR",
state: "Committed",
id: undefined,
Expand Down Expand Up @@ -843,6 +851,7 @@ const DetailWidget: React.FC<IDetailWidget> = ({
) {
return;
}
let txResponse: providers.TransactionResponse | undefined = undefined;
try {
onCommitPendingSignature();
const proxyContract = BosonSnapshotGate__factory.connect(
Expand Down Expand Up @@ -882,14 +891,15 @@ const DetailWidget: React.FC<IDetailWidget> = ({
: "0"
}
);
txResponse = tx;
onCommitPendingTransaction(tx.hash, false);
const receipt = await tx.wait();
const exchangeId = coreSDK.getCommittedExchangeIdFromLogs(
receipt.logs
) as string;
onCommitSuccess(receipt, { exchangeId });
} catch (error) {
onCommitError(error as Error);
onCommitError(error as Error, { txResponse });
}
};
return (
Expand Down
5 changes: 2 additions & 3 deletions src/components/seller/common/useOffersBacked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import { saveItemInStorage } from "../../../lib/utils/hooks/localstorage/useLoca
import { SellerExchangeProps } from "../../../lib/utils/hooks/useSellerDeposit";
import { WithSellerDataProps } from "./WithSellerData";

const THRESHOLD = 15;
export default function useOffersBacked({
funds: fundsData,
exchangesTokens: exchangesTokensData,
sellerDeposit: sellerDepositData
}: Pick<WithSellerDataProps, "funds" | "exchangesTokens" | "sellerDeposit">) {
const THRESHOLD = 15;

const { funds } = fundsData;
const { data: exchangesTokens } = exchangesTokensData;
const { data: sellersData } = sellerDepositData;
Expand Down Expand Up @@ -101,7 +100,7 @@ export default function useOffersBacked({
result = Number(
((Number(fund.availableAmount) / Number(backedFund)) * 100).toFixed(2)
);
result = Number.isNaN(result) ? 0 : result;
result = Number.isNaN(result) ? 100 : result;
}
return result;
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/seller/products/SellerProductsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const TagWrapper = styled.div`
padding: 0.5em 0.75em;
font-size: 0.75rem;
font-weight: 600;
white-space: pre;
white-space: pre-line;
`;

const VoidButton = styled(BosonButton)`
Expand Down
Loading