Skip to content

Commit be29a2b

Browse files
authored
Merge pull request #39 from openpeer/fix_quick_buy
Fix quick buy
2 parents e238912 + 2a31741 commit be29a2b

File tree

8 files changed

+774
-526
lines changed

8 files changed

+774
-526
lines changed

components/Buy/EscrowButton/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import { useAccount, useUserProfile } from "hooks";
44
//import { DEPLOYER_CONTRACTS } from 'models/networks';
55
import React, { useState } from "react";
66
//import { useContractRead, useNetwork } from 'wagmi';
7-
8-
import ApproveTokenButton from "./ApproveTokenButton";
9-
import DeploySellerContract from "./DeploySellerContract";
107
import { EscrowFundsParams } from "./EscrowButton.types";
118
import EscrowFundsButton from "./EscrowFundsButton";
129
import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
1310
import { useContractRead } from "@/hooks/transactions/useContractRead";
14-
import useEscrowFee from "@/hooks/useEscrowFee";
1511
import { User } from "@/models/types";
1612
import CreateEscrowAccount from "./CreateEscrowAccount";
1713

components/Buy/Release.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-mixed-spaces-and-tabs */
2-
/* eslint-disable @typescript-eslint/indent */
32
import StepLayout from 'components/Listing/StepLayout';
43
import HeaderH3 from 'components/SectionHeading/h3';
54
import React from 'react';

components/QuickBuy/Buy.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const Buy = ({ lists, updateLists, onSeeOptions, onLoading }: BuyProps) => {
2424
const [loading, setLoading] = useState(false);
2525
const [creatingAd, setCreatingAd] = useState(false);
2626
const router = useRouter();
27+
let changeInSelector=false;
2728

2829
const updateLoading = (l: boolean) => {
2930
setLoading(l);
@@ -38,6 +39,7 @@ const Buy = ({ lists, updateLists, onSeeOptions, onLoading }: BuyProps) => {
3839
fiatValue: number | undefined;
3940
}) => {
4041
if (!token || !currency || (!tokenValue && !fiatValue)) return;
42+
if(changeInSelector===false && ((fiatValue && fiatAmount===fiatValue)||(tokenValue && tokenAmount===tokenValue))) return;
4143
updateLoading(true);
4244
try {
4345
const params = {
@@ -63,9 +65,14 @@ const Buy = ({ lists, updateLists, onSeeOptions, onLoading }: BuyProps) => {
6365
const [list] = searchLists;
6466
const { price } = list || {};
6567
if (price) {
66-
if (tokenValue) setFiatAmount(tokenValue * price);
67-
if (fiatValue) setTokenAmount(truncate(fiatValue / price, token.decimals));
68+
if (tokenValue){
69+
setFiatAmount(tokenValue * price);
70+
}
71+
if (fiatValue){
72+
setTokenAmount(truncate(fiatValue / price, token.decimals));
73+
}
6874
} else {
75+
6976
// @ts-ignore
7077
if (fiatValue) setTokenAmount('');
7178
// @ts-ignore
@@ -74,25 +81,32 @@ const Buy = ({ lists, updateLists, onSeeOptions, onLoading }: BuyProps) => {
7481
} catch (error) {
7582
console.error(error);
7683
}
84+
changeInSelector=false;
7785
updateLoading(false);
7886
};
7987

8088
useEffect(() => {
89+
changeInSelector=true;
8190
search({ fiatValue: fiatAmount, tokenValue: undefined });
8291
}, [currency]);
8392

8493
useEffect(() => {
94+
changeInSelector=true;
8595
search({ fiatValue: undefined, tokenValue: tokenAmount });
8696
}, [token]);
8797

8898
const onChangeFiat = (val: number | undefined) => {
99+
console.log("Fiat Change");
100+
if(fiatAmount===val)return;
89101
setFiatAmount(val);
90102
if (val && token && currency) {
91103
search({ fiatValue: val, tokenValue: undefined });
92104
}
93105
};
94106

95107
const onChangeToken = (val: number | undefined) => {
108+
console.log("Token Change");
109+
if(tokenAmount===val)return;
96110
setTokenAmount(val);
97111
if (val && token && currency) {
98112
search({ fiatValue: undefined, tokenValue: val });
@@ -194,4 +208,4 @@ const Buy = ({ lists, updateLists, onSeeOptions, onLoading }: BuyProps) => {
194208
);
195209
};
196210

197-
export default Buy;
211+
export default Buy;

0 commit comments

Comments
 (0)