Skip to content

Commit

Permalink
Merge branch 'staging' into #1435/#1436/#1437-market-creation-clock-f…
Browse files Browse the repository at this point in the history
…ixes
  • Loading branch information
yornaath committed Jul 13, 2023
2 parents f81c17a + 2aa8d00 commit e5208f8
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 51 deletions.
2 changes: 1 addition & 1 deletion components/account/AccountSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const AccountSelect: FC<AccountSelectProps> = ({

{wallet.activeAccount?.address && (
<CopyIcon
copyText={wallet.activeAccount.address}
copyText={wallet.activeAccount?.address}
className="flex-grow pr-ztg-8"
size={16}
/>
Expand Down
2 changes: 1 addition & 1 deletion components/create/editor/inputs/Oracle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const OracleInput = forwardRef(
};

const isSelectedAccount = wallet.realAddress === value;
const proxy = wallet.proxyFor[wallet.activeAccount.address];
const proxy = wallet.proxyFor?.[wallet.activeAccount?.address];
const accountname =
proxy && proxy.enabled
? "Proxied"
Expand Down
4 changes: 2 additions & 2 deletions components/liquidity/ExitPoolForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useQueryClient } from "@tanstack/react-query";
import {
getIndexOf,
IOBaseAssetId,
IOCategoricalAssetId,
IOZtgAssetId,
isRpcSdk,
parseAssetId,
ZTG,
Expand Down Expand Up @@ -63,7 +63,7 @@ const ExitPoolForm = ({
const assetId = weight && parseAssetId(weight.assetId).unwrap();

return (
IOZtgAssetId.is(assetId) ||
IOBaseAssetId.is(assetId) ||
(IOCategoricalAssetId.is(assetId) &&
market.resolvedOutcome === getIndexOf(assetId).toString())
);
Expand Down
25 changes: 7 additions & 18 deletions components/menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,15 @@ const TopBar = () => {
<div className="block md:hidden">
<Menu.Item>
{({ active }) => (
<Link
href="/leaderboard"
onClick={(event) => {
event.preventDefault();
close();
}}
>
<Link href="/leaderboard" onClick={close}>
<button
disabled
className={`group flex w-full items-center px-2 py-2 text-sm gap-3 mb-4`}
>
<div className="relative h-6 w-6 opacity-30">
<div className="relative h-6 w-6">
<FiAward size={"100%"} />
</div>
<h3 className="text-sm font-semibold text-gray-400">
Leaderboard (coming soon)
<h3 className="text-sm font-semibold">
Leaderboard
</h3>
</button>
</Link>
Expand Down Expand Up @@ -155,17 +148,13 @@ const TopBar = () => {
</Menu>

<Link
type="button"
className="text-white cursor-default font-light relative hidden md:flex md:center gap-2"
className="text-white font-light relative hidden md:flex md:center gap-2"
href="/leaderboard"
onClick={(event) => {
event.preventDefault();
}}
>
<div className="relative h-6 w-6 opacity-40">
<div className="relative h-6 w-6">
<FiAward size={"100%"} />
</div>
<div className="text-gray-400">Leaderboard (coming soon)</div>
<div>Leaderboard</div>
</Link>
</div>
<AccountButton />
Expand Down
2 changes: 1 addition & 1 deletion components/portfolio/PortfolioIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const PortfolioIdentity = ({ address }: { address: string }) => {
const wallet = useWallet();
const { data: identity } = useIdentity(address);

const proxy = wallet.proxyFor?.[wallet.activeAccount.address];
const proxy = wallet.proxyFor?.[wallet.activeAccount?.address];

const isProxying = Boolean(
proxy && proxy.enabled && proxy.address === address,
Expand Down
12 changes: 12 additions & 0 deletions lib/constants/foreign-asset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BaseAssetId, IOForeignAssetId } from "@zeitgeistpm/sdk-next";
import { ChainName } from "./chains";

type ForeignAssetMetadata = {
Expand All @@ -19,6 +20,17 @@ export const lookupAssetImagePath = (foreignAssetId?: number | null) => {
}
};

export const lookupAssetSymbol = (baseAssetId?: BaseAssetId) => {
const foreignAssetId = IOForeignAssetId.is(baseAssetId)
? baseAssetId.ForeignAsset
: null;
if (foreignAssetId == null) {
return "ZTG";
} else {
return FOREIGN_ASSET_METADATA[foreignAssetId].tokenSymbol;
}
};

const BATTERY_STATION_FOREIGN_ASSET_METADATA: ForeignAssetMetadata = {
0: {
image: "/currencies/dot.png",
Expand Down
2 changes: 0 additions & 2 deletions lib/gql/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const marketQuery = gql`
question
slug
status
img
outcomeAssets
scalarType
creator
Expand Down Expand Up @@ -80,7 +79,6 @@ const marketQuery = gql`

export interface MarketPageIndexedData {
marketId: number;
img: string;
slug: string;
question: string;
description: string;
Expand Down
27 changes: 26 additions & 1 deletion lib/util/calc-scalar-winnings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
import { calcScalarWinnings } from "./calc-scalar-winnings";
import {
calcScalarResolvedPrices,
calcScalarWinnings,
} from "./calc-scalar-winnings";

describe("calcScalarWinnings", () => {
test("should calculate winnings correctly for short tokens", () => {
const winnings = calcScalarWinnings(0, 10, 5, 100, 0);
expect(winnings.toNumber()).toEqual(50);
});

test("should calculate winnings correctly for long tokens", () => {
const winnings = calcScalarWinnings(0, 40, 10, 0, 100);
expect(winnings.toNumber()).toEqual(25);
});

test("should calculate winnings correctly for both long and short tokens", () => {
const winnings = calcScalarWinnings(0, 40, 10, 100, 100);
expect(winnings.toNumber()).toEqual(100);
});

test("long value should be capped at 1 if resolved outcome is outside of bounds", () => {
const { longTokenValue } = calcScalarResolvedPrices(0, 40, 50);
expect(longTokenValue.toNumber()).toEqual(1);
});

test("long value should not fall below 0 if resolved outcome is outside of bounds", () => {
const { longTokenValue } = calcScalarResolvedPrices(10, 40, 0);
expect(longTokenValue.toNumber()).toEqual(0);
});

test("short value should not fall below 0 if resolved outcome is outside of bounds", () => {
const { shortTokenValue } = calcScalarResolvedPrices(0, 40, 50);
expect(shortTokenValue.toNumber()).toEqual(0);
});

test("short value should be capped at 1 resolved outcome is outside of bounds", () => {
const { shortTokenValue } = calcScalarResolvedPrices(10, 40, 0);
expect(shortTokenValue.toNumber()).toEqual(1);
});
});
16 changes: 14 additions & 2 deletions lib/util/calc-scalar-winnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ export const calcScalarResolvedPrices = (
.minus(lowerBound)
.div(priceRange);

const longTokenValue = resolvedNumberAsPercentage;
const shortTokenValue = new Decimal(1).minus(resolvedNumberAsPercentage);
const longTokenValue = constrainValue(resolvedNumberAsPercentage);
const shortTokenValue = constrainValue(
new Decimal(1).minus(resolvedNumberAsPercentage),
);

return { longTokenValue, shortTokenValue };
};

const constrainValue = (value: Decimal): Decimal => {
if (value.greaterThan(1)) {
return new Decimal(1);
} else if (value.lessThan(0)) {
return new Decimal(0);
} else {
return value;
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@zeitgeistpm/avatara-react": "^1.3.2",
"@zeitgeistpm/avatara-util": "^1.2.0",
"@zeitgeistpm/sdk": "^1.0.3",
"@zeitgeistpm/sdk-next": "npm:@zeitgeistpm/[email protected].20",
"@zeitgeistpm/sdk-next": "npm:@zeitgeistpm/[email protected].21",
"@zeitgeistpm/utility": "^2.18.12",
"axios": "^0.21.4",
"boring-avatars": "^1.6.1",
Expand Down
2 changes: 1 addition & 1 deletion pages/avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Avatar = () => {
const wallet = useWallet();

if (wallet.activeAccount) {
router.replace(`/avatar/${wallet.activeAccount.address}`);
router.replace(`/avatar/${wallet.activeAccount?.address}`);
return <></>;
}

Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function getStaticProps() {
categoryPlaceholders: categoryPlaceholders.map((c) => c.base64) ?? [],
bannerPlaceHolders: bannerPlaceHolders.map((c) => c.base64) ?? [],
},
revalidate: 10 * 60, //10min
revalidate: 1 * 60, //1min
};
}

Expand Down
Loading

0 comments on commit e5208f8

Please sign in to comment.