Skip to content

Commit

Permalink
update auction
Browse files Browse the repository at this point in the history
  • Loading branch information
nattadex committed Jul 22, 2024
1 parent 96695c8 commit dee350c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
49 changes: 49 additions & 0 deletions mobile-app/app/api/token/dusdt_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,52 @@ export function dusdt_converter_pair_data(pairData: any) {
},
};
}

export function dusdt_converter_auction(auctionData: any) {
return auctionData.map((auction: any) => {
return {
...auction,
collateralTokenSymbols: auction.collateralTokenSymbols.map(
(symbol: string) => symbol.replace(/dUSDT/g, updated_dusdt_name),
),
collaterals: auction.collaterals.map((collateral: any) => ({
...collateral,
name: collateral.name.replace(/USDT/g, updated_dusdt_name),
displaySymbol: collateral.displaySymbol.replace(
/dUSDT/g,
updated_dusdt_name,
),
})),
loan: {
...auction.loan,
name: auction.loan.name.replace(/USDT/g, updated_dusdt_name),
displaySymbol: auction.loan.displaySymbol.replace(
/dUSDT/g,
updated_dusdt_name,
),
},
auction: {
...auction.auction,
batches: auction.auction.batches.map((batch: any) => ({
...batch,
collaterals: batch.collaterals.map((collateral: any) => ({
...collateral,
name: collateral.name.replace(/USDT/g, updated_dusdt_name),
displaySymbol: collateral.displaySymbol.replace(
/dUSDT/g,
updated_dusdt_name,
),
})),
loan: {
...batch.loan,
name: batch.loan.name.replace(/USDT/g, updated_dusdt_name),
displaySymbol: batch.loan.displaySymbol.replace(
/dUSDT/g,
updated_dusdt_name,
),
},
})),
},
};
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
SkeletonLoaderScreen,
} from "@components/SkeletonLoader";
import { debounce } from "lodash";
import { dusdt_converter_auction } from "@api/token/dusdt_converter";
import { AuctionsParamList } from "./AuctionNavigator";
import { BrowseAuctions, ButtonGroupTabKey } from "./components/BrowseAuctions";
import { EmptyAuction } from "./components/EmptyAuction";
Expand All @@ -35,7 +36,7 @@ type Props = StackScreenProps<AuctionsParamList, "AuctionScreen">;

export function AuctionScreen({ navigation }: Props): JSX.Element {
const { hasFetchAuctionsData } = useSelector(
(state: RootState) => state.auctions
(state: RootState) => state.auctions,
);
const [showLoader, setShowLoader] = useState(true);
const [isFirstLoad, setIsFirstLoad] = useState(false);
Expand All @@ -44,35 +45,38 @@ export function AuctionScreen({ navigation }: Props): JSX.Element {
const [showSearchInput, setShowSearchInput] = useState(false);
const [searchString, setSearchString] = useState("");
const [isSearching, setIsSearching] = useState(false);
const batches = useSelector((state: RootState) =>
getAuctionBatches(state.auctions)
const batches = dusdt_converter_auction(
useSelector((state: RootState) => getAuctionBatches(state.auctions)),
);
const handleFilter = useCallback(
debounce((searchString: string) => {
setIsSearching(false);
if (searchString !== undefined && searchString.trim().length > 0) {
setFilteredAuctionBatches(
batches.filter((batch) =>
batches.filter((batch: AuctionBatchProps) =>
searchString
.trim()
.toLowerCase()
.split(" ")
.filter((e) => e !== "")
.every((i) =>
batch.collateralTokenSymbols.join(" ").toLowerCase().includes(i)
)
)
batch.collateralTokenSymbols
.join(" ")
.toLowerCase()
.includes(i),
),
),
);
} else {
setFilteredAuctionBatches([]);
}
}, 500),
[batches]
[batches],
);
const [filteredAuctionBatches, setFilteredAuctionBatches] =
useState<Array<AuctionBatchProps>>(batches);
const [activeButtonGroup, setActiveButtonGroup] = useState<ButtonGroupTabKey>(
ButtonGroupTabKey.AllBids
ButtonGroupTabKey.AllBids,
);
const blockCount = useSelector((state: RootState) => state.block.count);

Expand Down Expand Up @@ -159,7 +163,7 @@ export function AuctionScreen({ navigation }: Props): JSX.Element {

const handleButtonFilter = useCallback(
(buttonGroupTabKey: ButtonGroupTabKey) => {
const filteredAuctions = batches.filter((auction) => {
const filteredAuctions = batches.filter((auction: AuctionBatchProps) => {
switch (buttonGroupTabKey) {
case ButtonGroupTabKey.YourActiveBids:
return auction?.froms.includes(address);
Expand All @@ -176,7 +180,7 @@ export function AuctionScreen({ navigation }: Props): JSX.Element {
});
setFilteredAuctionBatches(filteredAuctions);
},
[batches, address]
[batches, address],
);

if (hasFetchAuctionsData && batches?.length === 0 && !showSearchInput) {
Expand Down Expand Up @@ -212,11 +216,11 @@ export function AuctionScreen({ navigation }: Props): JSX.Element {
? translate(
"screens/AuctionScreen",
"Search results for “{{input}}”",
{ input: searchString?.trim() }
{ input: searchString?.trim() },
)
: translate(
"screens/AuctionScreen",
"Search for auctions using collateral token names i.e. DFI DUSD dBTC."
"Search for auctions using collateral token names i.e. DFI DUSD dBTC.",
)}
</ThemedTextV2>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ export function VaultBanner({
<View style={tailwind("mt-3")}>
<TokenIconGroupV2
testID={`${testID}_collateral_token_group`}
symbols={vault.batches[0].collaterals?.map(
(collateral) => collateral.displaySymbol
symbols={vault.batches[0].collaterals?.map((collateral) =>
collateral.displaySymbol === "dUSDT"
? "ex_USDT"
: collateral.displaySymbol,
)}
maxIconToDisplay={6}
size={24}
Expand Down

0 comments on commit dee350c

Please sign in to comment.