This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87dac27
commit b83af0d
Showing
29 changed files
with
1,387 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
dist | ||
CHANGELOG.md | ||
packages/app/src/types | ||
contracts | ||
contracts | ||
**/*.typegen.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ yarn-lock.yaml | |
.github | ||
packages/contracts | ||
.pnpm-store | ||
.env | ||
.env | ||
**/*.typegen.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ ENV_FILE=.env | |
if [ ! -f "$FILE" ]; then | ||
cp .env.example $ENV_FILE | ||
fi | ||
|
||
pnpm xstate:typegen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./hooks"; | ||
export * from "./pages"; | ||
export * from "./utils"; | ||
export * from "./routes"; | ||
export * from "./hooks"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { toNumber } from 'fuels'; | ||
import { toBigInt, toNumber } from 'fuels'; | ||
|
||
import { ZERO } from '~/systems/Core'; | ||
import { divideFnValidOnly, ZERO } from '~/systems/Core'; | ||
import type { Maybe } from '~/types'; | ||
import type { PoolInfo } from '~/types/contracts/ExchangeContractAbi'; | ||
|
||
export const calculateRatio = ( | ||
initialFromAmount?: Maybe<bigint>, | ||
initialToAmount?: Maybe<bigint> | ||
) => { | ||
export function calculateRatio(initialFromAmount?: Maybe<bigint>, initialToAmount?: Maybe<bigint>) { | ||
const fromAmount = initialFromAmount || ZERO; | ||
const toAmount = initialToAmount || ZERO; | ||
const ratio = toNumber(fromAmount) / toNumber(toAmount); | ||
return Number.isNaN(ratio) || !Number.isFinite(ratio) ? 0 : ratio; | ||
}; | ||
} | ||
|
||
export function getPoolRatio(info?: PoolInfo) { | ||
const tokenReserve = toBigInt(info?.token_reserve || ZERO); | ||
const ethReserve = toBigInt(info?.eth_reserve || ZERO); | ||
return divideFnValidOnly(ethReserve, tokenReserve); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './helpers'; | ||
export * from './queries'; |
69 changes: 8 additions & 61 deletions
69
packages/app/src/systems/Swap/components/PricePerToken.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useSwap } from "../hooks/useSwap"; | ||
import { useSwapCoinInput } from "../hooks/useSwapCoinInput"; | ||
import { useSwapCoinSelector } from "../hooks/useSwapCoinSelector"; | ||
import { FROM_TO, TO_FROM } from "../machines/swapMachine"; | ||
|
||
import { CoinInput, CoinSelector } from "~/systems/Core"; | ||
import { InvertButton } from "~/systems/UI"; | ||
|
||
export function SwapWidget() { | ||
const { onInvertCoins } = useSwap(); | ||
const coinSelectorFromProps = useSwapCoinSelector(FROM_TO); | ||
const coinSelectorToProps = useSwapCoinSelector(TO_FROM); | ||
const coinInputFromProps = useSwapCoinInput(FROM_TO); | ||
const coinInputToProps = useSwapCoinInput(TO_FROM); | ||
|
||
return ( | ||
<> | ||
<div className="mt-4"> | ||
<CoinInput | ||
{...coinInputFromProps} | ||
rightElement={<CoinSelector {...coinSelectorFromProps} />} | ||
/> | ||
</div> | ||
<div className="flex items-center sm:justify-center -my-5"> | ||
<InvertButton onClick={onInvertCoins} /> | ||
</div> | ||
<div className="mb-4"> | ||
<CoinInput | ||
{...coinInputToProps} | ||
rightElement={<CoinSelector {...coinSelectorToProps} />} | ||
/> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useMemo } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
|
||
import { TOKENS } from "~/systems/Core"; | ||
|
||
export function useCoinByParam(coinDir: string) { | ||
const [searchParams] = useSearchParams([["coinFrom", "ETH"]]); | ||
const param = searchParams.get(coinDir); | ||
|
||
return useMemo(() => { | ||
if (param) { | ||
return TOKENS.find((t) => t.assetId === param || t.symbol === param); | ||
} | ||
}, [param]); | ||
} |
Oops, something went wrong.