Skip to content

Commit

Permalink
Merge pull request #70 from compolabs/feat/fetch-market-price
Browse files Browse the repository at this point in the history
[791]Added oracle for price index
  • Loading branch information
EchoDex authored Feb 23, 2024
2 parents 523fbda + f74ce50 commit af167cf
Show file tree
Hide file tree
Showing 20 changed files with 453 additions and 187 deletions.
2 changes: 1 addition & 1 deletion spark-frontend/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ module.exports = function (webpackEnv) {
// its runtime that would otherwise be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx|cjs)$/, /\.html$/, /\.json$/],
type: 'asset/resource',
},
// ** STOP ** Are you adding a new loader?
Expand Down
143 changes: 143 additions & 0 deletions spark-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion spark-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@emotion/styled": "^11.11.0",
"@ethersproject/bignumber": "^5.7.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@pythnetwork/pyth-evm-js": "^1.32.0",
"@svgr/webpack": "^5.5.0",
"@szhsin/react-accordion": "^1.2.3",
"@testing-library/jest-dom": "^5.17.0",
Expand Down Expand Up @@ -63,8 +64,8 @@
"react-app-polyfill": "^3.0.0",
"react-dev-utils": "^12.0.1",
"react-dom": "^18.2.0",
"react-modal-sheet": "^2.2.0",
"react-loading-skeleton": "^3.3.1",
"react-modal-sheet": "^2.2.0",
"react-popper-tooltip": "^4.4.2",
"react-refresh": "^0.11.0",
"react-router-dom": "^6.21.2",
Expand Down
48 changes: 24 additions & 24 deletions spark-frontend/src/components/TokenInput/AmountInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import React from "react";
import styled from "@emotion/styled";

type TProps = React.InputHTMLAttributes<HTMLInputElement> & {
small?: boolean;
onWheel?: React.WheelEventHandler<HTMLInputElement>;
onBlur?: React.FocusEventHandler<HTMLInputElement>;
onFocus?: React.FocusEventHandler<HTMLInputElement>;
inputRef?: React.RefObject<HTMLInputElement>;
};

const AmountInput: React.FC<TProps> = ({ onWheel, inputRef, ...props }) => (
<Root
{...props}
ref={inputRef}
small={props.small}
onBlur={props.onBlur}
onFocus={props.onFocus}
onWheel={(e) => {
e.target && (e.target as any).blur();
onWheel && onWheel(e);
}}
/>
);

export default AmountInput;

const Root = styled.input<{
small?: boolean;
}>`
Expand Down Expand Up @@ -30,27 +54,3 @@ const Root = styled.input<{
color: ${({ theme }) => theme.colors.textSecondary};
}
`;

type TProps = React.InputHTMLAttributes<HTMLInputElement> & {
small?: boolean;
onWheel?: React.WheelEventHandler<HTMLInputElement>;
onBlur?: React.FocusEventHandler<HTMLInputElement>;
onFocus?: React.FocusEventHandler<HTMLInputElement>;
inputRef?: React.RefObject<HTMLInputElement>;
};

const AmountInput: React.FC<TProps> = ({ onWheel, inputRef, ...props }) => (
<Root
{...props}
ref={inputRef}
small={props.small}
onBlur={props.onBlur}
onFocus={props.onFocus}
onWheel={(e) => {
e.target && (e.target as any).blur();
onWheel && onWheel(e);
}}
/>
);

export default AmountInput;
17 changes: 16 additions & 1 deletion spark-frontend/src/components/TokenInput/BigNumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useRef, useState } from "react";
import BigNumber from "bignumber.js";
import { Nullable } from "tsdef";

import { DEFAULT_DECIMALS } from "@src/constants";
Expand All @@ -23,6 +24,15 @@ export interface BigNumberInputProps {
displayDecimals?: number;
}

const BN_INPUT_CONFIG: BigNumber.Format = {
decimalSeparator: ".",
groupSeparator: "",
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: " ",
fractionGroupSize: 0,
};

export const BigNumberInput: React.FC<BigNumberInputProps> = ({
decimals = DEFAULT_DECIMALS,
displayDecimals: _displayDecimals,
Expand Down Expand Up @@ -52,7 +62,12 @@ export const BigNumberInput: React.FC<BigNumberInputProps> = ({
const parseInputValue = BN.parseUnits(inputValue || BN.ZERO, decimals);

if (!parseInputValue.eq(value)) {
setInputValue(BN.formatUnits(value, decimals).toSignificant(displayDecimals));
const formattedValue = BN.formatUnits(value, decimals).toSignificant(
displayDecimals,
undefined,
BN_INPUT_CONFIG,
);
setInputValue(formattedValue);
}
}
}, [value, decimals, inputValue, displayDecimals]);
Expand Down
Loading

0 comments on commit af167cf

Please sign in to comment.