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

fix: abacus input types should always be string #1222

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
} from '@/state/inputs';
import { getTransferInputs } from '@/state/inputsSelectors';

import { assertNever } from '../assertNever';
import { LocaleSeparators } from '../numbers';
import { testFlags } from '../testFlags';
import AbacusAnalytics from './analytics';
Expand All @@ -75,6 +76,24 @@ import AbacusStateNotifier from './stateNotification';
import AbacusThreading from './threading';
import AbacusWebsocket from './websocket';

type AbacusInputValue = string | number | boolean | null | undefined;
function abacusValueToString(val: AbacusInputValue): Nullable<string> {
if (val == null) {
return val;
}
if (typeof val === 'number') {
return val.toString();
}
if (typeof val === 'string') {
return val;
}
if (typeof val === 'boolean') {
return val ? 'true' : 'false';
}
assertNever(val);
return val?.toString() ?? '';
}

class AbacusStateManager {
private store: RootStore | undefined;

Expand Down Expand Up @@ -319,26 +338,44 @@ class AbacusStateManager {
this.chainTransactions.setSelectedGasDenom(denom);
};

setTradeValue = ({ value, field }: { value: any; field: Nullable<TradeInputFields> }) => {
this.stateManager.trade(value, field);
setTradeValue = ({
value,
field,
}: {
value: AbacusInputValue;
field: Nullable<TradeInputFields>;
}) => {
this.stateManager.trade(abacusValueToString(value), field);
};

setAdjustIsolatedMarginValue = ({
value,
field,
}: {
value: any;
value: AbacusInputValue;
field: AdjustIsolatedMarginInputFields;
}) => {
this.stateManager.adjustIsolatedMargin(value, field);
this.stateManager.adjustIsolatedMargin(abacusValueToString(value), field);
};

setTransferValue = ({ value, field }: { value: any; field: TransferInputFields }) => {
this.stateManager.transfer(value, field);
setTransferValue = ({
value,
field,
}: {
value: AbacusInputValue;
field: TransferInputFields;
}) => {
this.stateManager.transfer(abacusValueToString(value), field);
};

setTriggerOrdersValue = ({ value, field }: { value: any; field: TriggerOrdersInputFields }) => {
this.stateManager.triggerOrders(value, field);
setTriggerOrdersValue = ({
value,
field,
}: {
value: AbacusInputValue;
field: TriggerOrdersInputFields;
}) => {
this.stateManager.triggerOrders(abacusValueToString(value), field);
};

setHistoricalPnlPeriod = (
Expand All @@ -364,8 +401,14 @@ class AbacusStateManager {
}
};

setClosePositionValue = ({ value, field }: { value: any; field: ClosePositionInputFields }) => {
this.stateManager.closePosition(value, field);
setClosePositionValue = ({
value,
field,
}: {
value: AbacusInputValue;
field: ClosePositionInputFields;
}) => {
this.stateManager.closePosition(abacusValueToString(value), field);
};

setLocaleSeparators = ({ group, decimal }: LocaleSeparators) => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/forms/ClosePositionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const ClosePositionForm = ({
</$MidPriceButton>
);

const onUseLimitCheckedChange = (checked: Boolean) => {
const onUseLimitCheckedChange = (checked: boolean) => {
abacusStateManager.setClosePositionValue({
value: checked,
field: ClosePositionInputField.useLimit,
Expand Down
Loading