Skip to content

Commit

Permalink
♻️ refactor components && fetch token vault informations
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Burg committed Oct 18, 2023
1 parent 4b29f2d commit 526af74
Show file tree
Hide file tree
Showing 54 changed files with 800 additions and 600 deletions.
40 changes: 20 additions & 20 deletions batcher-ui/src/actions/events.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { BigMapEvent } from 'src/types/events';
import type { BigMapEvent } from '@/types';

export const newEvent = (event: BigMapEvent) =>
({
type: 'NEW_EVENT',
payload: { event },
} as const);

export const closeToast = () =>
({
type: 'CLOSE_TOAST',
} as const);
export const closeToast = () =>
({
type: 'CLOSE_TOAST',
} as const);

export const newError = (errorContent: string) =>
({
type: 'NEW_ERROR',
payload: { errorContent },
} as const);
export const newError = (errorContent: string) =>
({
type: 'NEW_ERROR',
payload: { errorContent },
} as const);

export const newInfo = (infoContent: string) =>
({
type: 'NEW_INFO',
payload: { infoContent },
} as const);
export const newInfo = (infoContent: string) =>
({
type: 'NEW_INFO',
payload: { infoContent },
} as const);

export type EventActions =
| ReturnType<typeof newEvent>
| ReturnType<typeof newError>
| ReturnType<typeof newInfo>
| ReturnType<typeof closeToast>;
export type EventActions =
| ReturnType<typeof newEvent>
| ReturnType<typeof newError>
| ReturnType<typeof newInfo>
| ReturnType<typeof closeToast>;
2 changes: 1 addition & 1 deletion batcher-ui/src/actions/exchange.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BatcherStatus, CurrentSwap, PriceStrategy } from '../types';
import { BatcherStatus, CurrentSwap, PriceStrategy } from '@/types';

export const updatePriceStrategy = (priceStrategy: PriceStrategy) =>
({
Expand Down
2 changes: 1 addition & 1 deletion batcher-ui/src/actions/holdings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HoldingsState } from 'src/types';
import { HoldingsState } from '@/types';

export const redeem = () =>
({
Expand Down
41 changes: 35 additions & 6 deletions batcher-ui/src/actions/marketholdings.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { MarketHoldingsState } from 'src/types';
import { MarketHoldingsState } from '@/types';

export const addLiquidity = () =>
({
type: 'ADDLIQUIDITY',
}) as const;
} as const);

export const removeLiquidity = () =>
({
type: 'REMOVELIQUIDITY',
}) as const;
} as const);

export const claimRewards = () =>
({
type: 'CLAIMREWARDS',
}) as const;
} as const);

export const updateMarketHoldings = (
vaults: Partial<Omit<MarketHoldingsState, 'currentVault'>>
Expand All @@ -30,18 +30,47 @@ export const getMarketHoldings = (
({
type: 'GET_MARKET_HOLDINGS',
payload: { contractAddress, userAddress },
}) as const;
} as const);

export const changeVault = (vault: string) =>
({
type: 'CHANGE_VAULT',
payload: { vault },
}) as const;
} as const);

// ---- WIP ---- //

export const getUserVault = (userAddress: string) =>
({
type: 'GET_USER_VAULT',
payload: { userAddress },
} as const);

export const updateUserVault = (vault: any) =>
({
type: 'UPDATE_USER_VAULT',
payload: { vault },
} as const);

export const getGlobalVault = () =>
({
type: 'GET_GLOBAL_VAULT',
} as const);

export const updateGlobalVault = (vault: any) =>
({
type: 'UPDATE_GLOBAL_VAULT',
payload: { vault },
} as const);

export type MarketHoldingsActions =
| ReturnType<typeof addLiquidity>
| ReturnType<typeof removeLiquidity>
| ReturnType<typeof claimRewards>
| ReturnType<typeof changeVault>
| ReturnType<typeof getMarketHoldings>
| ReturnType<typeof getUserVault>
| ReturnType<typeof updateUserVault>
| ReturnType<typeof getGlobalVault>
| ReturnType<typeof updateGlobalVault>
| ReturnType<typeof updateMarketHoldings>;
3 changes: 1 addition & 2 deletions batcher-ui/src/actions/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// import { Option } from 'fp-ts/Option';
import { Balances } from 'src/utils/utils';
import { Balances } from '@/utils/utils';

const connectedWallet = ({ userAddress }: { userAddress: string }) =>
({
Expand Down
16 changes: 10 additions & 6 deletions batcher-ui/src/commands/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import {
updateVolumes,
updateOraclePrice,
updateBatcherStatus,
} from 'src/actions';
import { updateHoldings } from 'src/actions/holdings';
import { userAddressSelector } from 'src/reducers';
import { BatchBigmap, OrderBookBigmap, RatesCurrentBigmap } from 'src/types';
import { BigMapEvent } from 'src/types/events';
} from '@/actions';
import { updateHoldings } from '@/actions/holdings';
import { userAddressSelector } from '@/reducers';
import type {
BatchBigmap,
OrderBookBigmap,
RatesCurrentBigmap,
BigMapEvent,
} from '@/types';
import {
computeAllHoldings,
computeOraclePrice,
mapStatus,
toVolumes,
} from 'src/utils/utils';
} from '@/utils/utils';

export const newEventCmd = (event: BigMapEvent) => {
return Cmd.run(
Expand Down
6 changes: 3 additions & 3 deletions batcher-ui/src/commands/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getPairsInformations,
getVolumes,
getTimeDifferenceInMs,
} from '../utils/utils';
} from '@/utils/utils';
import {
updateBatchNumber,
updateBatcherStatus,
Expand All @@ -18,8 +18,8 @@ import {
updateRemainingTime,
noBatchError,
newError,
} from '../actions';
import { BatcherStatus, CurrentSwap, SwapNames } from 'src/types';
} from '@/actions';
import { BatcherStatus, CurrentSwap, SwapNames } from '@/types';

const fetchPairInfosCmd = (pair: string) =>
Cmd.run(
Expand Down
6 changes: 3 additions & 3 deletions batcher-ui/src/commands/holdings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Cmd } from 'redux-loop';
import { getOrdersBook } from '../utils/utils';
import { updateHoldings } from 'src/actions/holdings';
import { newError } from 'src/actions';
import { getOrdersBook } from '@/utils/utils';
import { updateHoldings } from '@/actions/holdings';
import { newError } from '@/actions';

const fetchHoldingsCmd = (userAddress?: string) => {
return Cmd.run(
Expand Down
40 changes: 36 additions & 4 deletions batcher-ui/src/commands/marketholdings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Cmd } from 'redux-loop';
import { getMarketHoldings } from '../utils/utils';
import { updateMarketHoldings } from 'src/actions';
import {
getGlobalVault,
getMarketHoldings,
getUserVault2,
} from '@/utils/market-maker';
import {
updateGlobalVault,
updateMarketHoldings,
updateUserVault,
} from '@/actions';

const fetchMarketHoldingsCmd = (
contractAddress: string,
Expand All @@ -9,7 +17,6 @@ const fetchMarketHoldingsCmd = (
return Cmd.run(
async () => {
const vaults = await getMarketHoldings(userAddress || '');

return vaults;
},
{
Expand All @@ -18,4 +25,29 @@ const fetchMarketHoldingsCmd = (
);
};

export { fetchMarketHoldingsCmd };
const fetchUserVaultCmd = (userAddress: string, tokenName: string) => {
return Cmd.run(
async () => {
const userVault = await getUserVault2(userAddress, tokenName);
return userVault;
},
{
successActionCreator: updateUserVault,
}
);
};

const fetchGlobalVaultCmd = (tokenName: string) => {
return Cmd.run(
async () => {
const globalVault = await getGlobalVault(tokenName);

return globalVault;
},
{
successActionCreator: updateGlobalVault,
}
);
};

export { fetchMarketHoldingsCmd, fetchUserVaultCmd, fetchGlobalVaultCmd };
4 changes: 2 additions & 2 deletions batcher-ui/src/commands/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cmd } from 'redux-loop';
import { getBalances } from '../utils/utils';
import { gotUserBalances } from '../actions';
import { getBalances } from '@/utils/utils';
import { gotUserBalances } from '@/actions';

const fetchUserBalancesCmd = (userAddress?: string) => {
return Cmd.run(
Expand Down
Loading

0 comments on commit 526af74

Please sign in to comment.