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

Pulling refs/heads/staging into test-staging #1560

Merged
merged 12 commits into from
Jul 14, 2023
27 changes: 11 additions & 16 deletions components/account/AccountButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,18 @@ const AccountButton: FC<{
<label className="text-purple-900 text-xs italic mb-2">
Account is acting proxy for:
</label>
{realAddress && (
<div className="flex items-center gap-1">
<div className="text-white text-sm">
{shortenAddress(
realAddress,
7,
7,
)}
</div>
<div className="text-purple-800">
<CopyIcon
size={14}
copyText={realAddress}
/>
</div>
<div className="flex items-center gap-1">
<div className="text-white text-sm">
{realAddress &&
shortenAddress(realAddress, 7, 7)}
</div>
)}
<div className="text-purple-800">
<CopyIcon
size={14}
copyText={realAddress}
/>
</div>
</div>
</div>
</div>
</div>
Expand Down
43 changes: 23 additions & 20 deletions components/liquidity/LiquidityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ const LiquidityModal = ({

return allBalances;
}
return {};
}, [
pool?.weights,
userAssetBalances,
Expand All @@ -142,27 +141,31 @@ const LiquidityModal = ({

<Tab.Panels className="p-[30px]">
<Tab.Panel>
<JoinPoolForm
poolId={poolId}
poolBalances={allBalances}
totalPoolShares={
new Decimal(totalPoolIssuance?.toString() ?? 0)
}
baseAssetTicker={metadata?.symbol}
onSuccess={onClose}
/>
{allBalances && (
<JoinPoolForm
poolId={poolId}
poolBalances={allBalances}
totalPoolShares={
new Decimal(totalPoolIssuance?.toString() ?? 0)
}
baseAssetTicker={metadata?.symbol}
onSuccess={onClose}
/>
)}
</Tab.Panel>
<Tab.Panel>
<ExitPoolForm
poolId={poolId}
poolBalances={allBalances}
totalPoolShares={
new Decimal(totalPoolIssuance?.toString() ?? 0)
}
userPoolShares={new Decimal(userPoolTokens?.toString() ?? 0)}
baseAssetTicker={metadata?.symbol}
onSuccess={onClose}
/>
{allBalances && (
<ExitPoolForm
poolId={poolId}
poolBalances={allBalances}
totalPoolShares={
new Decimal(totalPoolIssuance?.toString() ?? 0)
}
userPoolShares={new Decimal(userPoolTokens?.toString() ?? 0)}
baseAssetTicker={metadata?.symbol}
onSuccess={onClose}
/>
)}
</Tab.Panel>
</Tab.Panels>
</Tab.Group>
Expand Down
13 changes: 7 additions & 6 deletions components/markets/MarketHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { formatScalarOutcome } from "lib/util/format-scalar-outcome";
import { Dialog } from "@headlessui/react";
import { usePoolLiquidity } from "lib/hooks/queries/usePoolLiquidity";
import { estimateMarketResolutionDate } from "lib/util/estimate-market-resolution";
import { MarketReport } from "lib/types";

export const UserIdentity: FC<
PropsWithChildren<{ user: string; className?: string }>
Expand Down Expand Up @@ -280,10 +281,10 @@ const MarketHistory: FC<

const MarketHeader: FC<{
market: MarketPageIndexedData;
report: MarketDispute;
disputes: MarketDispute;
resolvedOutcome: string;
token: string;
report?: MarketReport;
disputes?: MarketDispute;
resolvedOutcome?: string;
token?: string;
marketStage: MarketStage;
rejectReason?: string;
}> = ({
Expand Down Expand Up @@ -316,10 +317,10 @@ const MarketHeader: FC<{
marketType,
categories,
status,
scalarType,
disputes,
report,
resolvedOutcome,
scalarType,
);

const { data: marketHistory } = useMarketEventHistory(
Expand Down Expand Up @@ -418,7 +419,7 @@ const MarketHeader: FC<{
<MarketOutcome
setShowMarketHistory={setShowMarketHistory}
status={status}
outcome={outcome}
outcome={outcome ?? ""}
by={by}
marketHistory={marketHistory}
/>
Expand Down
2 changes: 1 addition & 1 deletion components/markets/MarketsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const MarketsList = ({ className = "" }: MarketsListProps) => {
const filteredScalar =
scalar?.filter((item): item is string => item !== null) ?? [];
const marketType = { categorical, scalar: filteredScalar };
const pool = market.pool ?? {};
const pool = market.pool ?? null;
const tags =
market.tags?.filter((tag): tag is string => tag !== null) ?? [];

Expand Down
16 changes: 10 additions & 6 deletions components/markets/ScalarPriceRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interface ScalarPriceRangeProps {
scalarType: ScalarRangeType;
lowerBound: number;
upperBound: number;
shortPrice: number; //between 0 and 1
longPrice: number; //between 0 and 1
shortPrice?: number; //between 0 and 1
longPrice?: number; //between 0 and 1
status: string;
}

Expand All @@ -20,12 +20,16 @@ const ScalarPriceRange = ({
status,
}: ScalarPriceRangeProps) => {
const { width = 0, ref } = useResizeDetector();
const shortPercentage = 1 - shortPrice;
const shortPercentage = shortPrice && 1 - shortPrice;
const longPercentage = longPrice;
const averagePercentage = (shortPercentage + longPercentage) / 2;
const averagePosition = width * averagePercentage;
const averagePercentage =
shortPercentage && longPercentage && (shortPercentage + longPercentage) / 2;
const averagePosition = averagePercentage && width * averagePercentage;

const position = useMemo(() => {
if (!shortPrice || !longPrice) {
return 0;
}
const pos =
(upperBound - lowerBound) * ((1 - shortPrice + longPrice) / 2) +
lowerBound;
Expand Down Expand Up @@ -66,7 +70,7 @@ const ScalarPriceRange = ({
<div
style={{
width: `${
isNaN(averagePosition) || Number(positionDisplay) === 0
averagePosition != null || Number(positionDisplay) === 0
? 0
: averagePosition
}px`,
Expand Down
2 changes: 1 addition & 1 deletion components/markets/market-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface IndexedMarketCardData {
scalarType: ScalarRangeType;
prediction: { name: string; price: number };
volume: number;
pool: {};
pool: { poolId?: number; volume: string } | null;
baseAsset: string;
tags?: string[];
status: string;
Expand Down
2 changes: 1 addition & 1 deletion components/portfolio/DepositButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const DepositModal = ({

const { send: transfer, isLoading } = useCrossChainExtrinsic(
() => {
if (!chain || !api || !wallet.activeAccount || !constants) return;
if (!chain || !api || !wallet.realAddress || !constants) return;
const tx = chain.createDepositExtrinsic(
api,
wallet.realAddress,
Expand Down
2 changes: 1 addition & 1 deletion components/portfolio/WithdrawButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const WithdrawModal = ({

const { send: transfer, isLoading } = useCrossChainExtrinsic(
() => {
if (isRpcSdk(sdk) && wallet.activeAccount) {
if (isRpcSdk(sdk) && wallet.realAddress) {
const tx = createWithdrawExtrinsic(
sdk.api,
amountDecimal.toFixed(0),
Expand Down
5 changes: 4 additions & 1 deletion components/ui/CopyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FC, Fragment, useEffect, useState } from "react";
import { Copy } from "react-feather";

export type CopyIconProps = {
copyText: string;
copyText?: string;
className?: string;
size?: number;
};
Expand All @@ -16,6 +16,9 @@ const CopyIcon: FC<CopyIconProps> = ({
const [recentlyCopied, setRecentlyCopied] = useState(false);

const copyAddressToClipboard = () => {
if (copyText == null) {
return;
}
navigator.clipboard.writeText(copyText);
setRecentlyCopied(true);
};
Expand Down
4 changes: 2 additions & 2 deletions e2e/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ test.describe("index page", () => {

const numSlides = images.length;

let lastTitle: string;
let lastSubTitle: string;
let lastTitle: string | null = null;
let lastSubTitle: string | null = null;
for (let index = 0; index < numSlides; index++) {
expect(await indexPage.getActiveSlideIndex()).toBe(index);
const title = await heroSlider.locator("h2").last().textContent();
Expand Down
2 changes: 1 addition & 1 deletion e2e/lib/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IGNORED_MESSAGES = [

const test = base.extend<{ consoleErrors: string[] }>({
consoleErrors: async ({ page }, use) => {
const logs = [];
const logs: string[] = [];

page.on("pageerror", (error) => {
for (const ignoredMessage of IGNORED_MESSAGES) {
Expand Down
3 changes: 2 additions & 1 deletion lib/gql/featured-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getFeaturedMarketIds } from "lib/cms/get-featured-marketids";
import { getCurrentPrediction } from "lib/util/assets";
import { hiddenMarketIds } from "lib/constants/markets";
import { marketMetaFilter } from "./constants";
import { isPresent } from "lib/types";

const marketQuery = gql`
query Market($marketId: Int) {
Expand Down Expand Up @@ -167,7 +168,7 @@ const getFeaturedMarkets = async (
}),
);

return featuredMarkets.filter((market) => market !== undefined);
return featuredMarkets.filter(isPresent);
};

export default getFeaturedMarkets;
23 changes: 19 additions & 4 deletions lib/gql/markets-list/outcomes-for-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ const assetsQuery = gql`
}
`;

const isValidCategory = (
category?: {
color?: string | null;
name?: string | null;
} | null,
): category is { color?: string; name: string } => {
return category != null && typeof category.name === "string";
};

export const getOutcomesForMarkets = async (
client: GraphQLClient,
markets: {
pool?: { poolId: number };
pool?: { poolId: number } | null;
marketId: number;
marketType: { categorical?: string; scalar?: string[] };
categories?: { color?: string; name?: string }[];
marketType: {
categorical?: string | null;
scalar?: (null | string)[] | null;
};
categories?: { color?: string | null; name?: string | null }[] | null;
}[],
): Promise<{ [marketId: number]: MarketOutcomes }> => {
if (markets.length === 0) {
Expand Down Expand Up @@ -63,7 +75,7 @@ export const getOutcomesForMarkets = async (

const res = { ...prev };

let currentOutcomes = [];
let currentOutcomes: MarketOutcomes = [];

for (const asset of filteredAssets) {
const assetIdJson = JSON.parse(asset.assetId);
Expand All @@ -76,6 +88,9 @@ export const getOutcomesForMarkets = async (
}

const category = categories?.[categoryIndex];
if (!isValidCategory(category)) {
continue;
}
const currentOutcome = {
...category,
price: asset.price,
Expand Down
2 changes: 1 addition & 1 deletion lib/gql/trending-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const getTrendingMarkets = async (
volume: Number(new Decimal(market.pool.volume).div(ZTG).toFixed(0)),
baseAsset: market.baseAsset,
outcomes: marketCategories,
pool: market.pool,
pool: market.pool ?? null,
marketType: market.marketType,
tags: market.tags,
status: market.status,
Expand Down
6 changes: 3 additions & 3 deletions lib/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { fromEvent, Subscription } from "rxjs";
import { debounceTime } from "rxjs/operators";

Expand All @@ -7,7 +7,7 @@ export const useEvent = (
eventName: string,
debounceMs: number = 0,
) => {
const eventSub = useRef<Subscription>(null);
const eventSub = useRef<Subscription | null>(null);
const [event, setEvent] = useState<Event>();

useEffect(() => {
Expand All @@ -20,7 +20,7 @@ export const useEvent = (
eventSub.current = fromEvent(target, eventName)
.pipe(debounceTime(debounceMs))
.subscribe((e: Event) => setEvent(e));
return () => eventSub.current.unsubscribe();
return () => eventSub.current?.unsubscribe();
}, [target]);

return event;
Expand Down
18 changes: 12 additions & 6 deletions lib/hooks/slides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,31 @@ export const useSliderControls = (props: UseSlidesProps): UseSliderControls => {
const isFirstSlide = currentSlide === props.count - 1;
const newSlide = isFirstSlide ? 0 : currentSlide + 1;
setCurrentSlide(newSlide);
userOrigin && pause(props.pauseOnUserInteraction);
userOrigin &&
props.pauseOnUserInteraction &&
pause(props.pauseOnUserInteraction);
};

const prev = (userOrigin?: boolean) => {
const isFirstSlide = currentSlide === 0;
const newSlide = isFirstSlide ? props.count - 1 : currentSlide - 1;
setCurrentSlide(newSlide);
userOrigin && pause(props.pauseOnUserInteraction);
userOrigin &&
props.pauseOnUserInteraction &&
pause(props.pauseOnUserInteraction);
};

const goto = (slide: number, userOrigin?: boolean) => {
setCurrentSlide(slide);
userOrigin && pause(props.pauseOnUserInteraction);
userOrigin &&
props.pauseOnUserInteraction &&
pause(props.pauseOnUserInteraction);
};

const pause = (time: number) => {
clearTimeout(timerRef.current);
timerRef.current && clearTimeout(timerRef.current);
setPaused(true);
clearTimeout(pauseTimerRef.current);
pauseTimerRef.current && clearTimeout(pauseTimerRef.current);
pauseTimerRef.current = setTimeout(() => {
setPaused(false);
}, time);
Expand All @@ -64,7 +70,7 @@ export const useSliderControls = (props: UseSlidesProps): UseSliderControls => {
next();
}, props.autoplay);
return () => {
clearTimeout(timerRef.current);
timerRef.current && clearTimeout(timerRef.current);
};
}
}, [props.autoplay, currentSlide, paused]);
Expand Down
Loading