mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-25 10:29:14 +00:00
88532cdc3c
* progress * Normalize bity api response * Filter api response * Track swap information in component state * Update dropdown onchange * remove dead code * Update Min Max Validation * Update minmax err msg && fix onChangeOriginKind * Add origin & destination to redux state * Update types & Update tests * Update types * Update swap.spec.ts test * Remove commented out code * Remove hardcoded coin array * Create types.ts for swap reducer * Update swapinput type * Update bityRates in localStorage & Replace all instances of ...Kind / ...Amount props * Add shapeshift banner * initial work for sagas * Update Types * Update swap reducer initial state * Update Types & Store empty obj for bityRates / options * Update more types * added shapeshift file and rates comments * action reducers and prop mapping to components * add typings and swap icon * more actions reducers and sagas * debugging shapeshift service * add Headers * Fix content type * add order reset saga and ui fixes * remove console log and swap b/w Bity and Shapeshift * working state for Shapeshift and Bity - tested with mainnet * add icon component * UI improvements and fix select bug * fix timer bug * add bity fallback options and toFixed floats * tslint errors * add arrow to dropdown and add support footer * Add service provider * fix minor $ bug and stop timer on order complete * better load UX and dropdown UX * fixed single test * currRate prop bugs and reduce LS bloat * takeEvery on timer saga and don't clear state.options to restartSwap reducer * export tx sagas and fix minor type * Add ShapeShift Rates functionality when selecting a ShapeShift pair. * type fixes * BugFix: Don't change displayed ShapeShift Rate Inputs on every dropdown change Also contains some caching / performance improvements * BugFix: Don't remote rate inputs when falsy amount * fix type error * Progress commit * Implement saga logic * Make address field factory component * Shorten debounce time * Make new actions / sagas for handling single token lookup * Implement working version of litesend * Change saga into selector * Add failing spec * fix broken test * add debounce to error message * fix tests * update snapshots * test coverage * move setState disabled property from debounce so we instantly can go to next step on valid amounts * much deeper test coverage, fix debounce ux, and fix bity flashing at swap page load * fix minor failing test * seperate shapeshift erc20 token whitelist * fix saveState store bug * break orderTimeRemaining saga up and rewrite tests * add new swap icon * remove unused allowReadOnly prop * change offlineaware to walletdecrypt for litesend * fix LiteSend changewallet bug * fix error message UX * fix button styling to match develop * fix liteSend test * Fix LiteSend UX on unavl tokens, dropdown null value, and don't show decrypt in litesend after successful wallet decrypt. * add litesend network check
168 lines
4.2 KiB
TypeScript
168 lines
4.2 KiB
TypeScript
import { SetBalanceFullfilledAction } from 'actions/wallet/actionTypes';
|
|
import {
|
|
SetTokenBalancesFulfilledAction,
|
|
SetWalletAction,
|
|
WalletAction,
|
|
SetWalletConfigAction,
|
|
TypeKeys,
|
|
SetTokenBalanceFulfilledAction
|
|
} from 'actions/wallet';
|
|
import { TokenValue } from 'libs/units';
|
|
import { IWallet, Balance, WalletConfig } from 'libs/wallet';
|
|
|
|
export interface State {
|
|
inst?: IWallet | null;
|
|
config?: WalletConfig | null;
|
|
// in ETH
|
|
balance: Balance | { wei: null };
|
|
tokens: {
|
|
[key: string]: {
|
|
balance: TokenValue;
|
|
error: string | null;
|
|
};
|
|
};
|
|
isTokensLoading: boolean;
|
|
tokensError: string | null;
|
|
hasSavedWalletTokens: boolean;
|
|
}
|
|
|
|
export const INITIAL_STATE: State = {
|
|
inst: null,
|
|
config: null,
|
|
balance: { isPending: false, wei: null },
|
|
tokens: {},
|
|
isTokensLoading: false,
|
|
tokensError: null,
|
|
hasSavedWalletTokens: true
|
|
};
|
|
|
|
function setWallet(state: State, action: SetWalletAction): State {
|
|
return {
|
|
...state,
|
|
inst: action.payload,
|
|
config: INITIAL_STATE.config,
|
|
balance: INITIAL_STATE.balance,
|
|
tokens: INITIAL_STATE.tokens
|
|
};
|
|
}
|
|
|
|
function setBalancePending(state: State): State {
|
|
return { ...state, balance: { ...state.balance, isPending: true } };
|
|
}
|
|
|
|
function setBalanceFullfilled(state: State, action: SetBalanceFullfilledAction): State {
|
|
return {
|
|
...state,
|
|
balance: { wei: action.payload, isPending: false }
|
|
};
|
|
}
|
|
|
|
function setBalanceRejected(state: State): State {
|
|
return { ...state, balance: { ...state.balance, isPending: false } };
|
|
}
|
|
|
|
function setTokenBalancesPending(state: State): State {
|
|
return {
|
|
...state,
|
|
tokens: {},
|
|
isTokensLoading: true,
|
|
tokensError: null
|
|
};
|
|
}
|
|
|
|
function setTokenBalancePending(state: State): State {
|
|
return {
|
|
...state,
|
|
isTokensLoading: true,
|
|
tokensError: null
|
|
};
|
|
}
|
|
|
|
function setTokenBalanceFufilled(state: State, action: SetTokenBalanceFulfilledAction): State {
|
|
return {
|
|
...state,
|
|
tokens: { ...state.tokens, ...action.payload },
|
|
isTokensLoading: false
|
|
};
|
|
}
|
|
|
|
function setTokenBalanceRejected(state: State): State {
|
|
return {
|
|
...state,
|
|
isTokensLoading: false,
|
|
tokensError: 'Failed to fetch token value'
|
|
};
|
|
}
|
|
|
|
function setTokenBalancesFulfilled(state: State, action: SetTokenBalancesFulfilledAction): State {
|
|
return {
|
|
...state,
|
|
tokens: action.payload,
|
|
isTokensLoading: false
|
|
};
|
|
}
|
|
|
|
function setTokenBalancesRejected(state: State): State {
|
|
return {
|
|
...state,
|
|
isTokensLoading: false,
|
|
tokensError: 'Failed to fetch token values'
|
|
};
|
|
}
|
|
|
|
function scanWalletForTokens(state: State): State {
|
|
return {
|
|
...state,
|
|
hasSavedWalletTokens: false
|
|
};
|
|
}
|
|
|
|
function setWalletTokens(state: State): State {
|
|
return {
|
|
...state,
|
|
hasSavedWalletTokens: true
|
|
};
|
|
}
|
|
|
|
function setWalletConfig(state: State, action: SetWalletConfigAction): State {
|
|
return {
|
|
...state,
|
|
config: action.payload
|
|
};
|
|
}
|
|
|
|
export function wallet(state: State = INITIAL_STATE, action: WalletAction): State {
|
|
switch (action.type) {
|
|
case TypeKeys.WALLET_SET:
|
|
return setWallet(state, action);
|
|
case TypeKeys.WALLET_RESET:
|
|
return INITIAL_STATE;
|
|
case TypeKeys.WALLET_SET_BALANCE_PENDING:
|
|
return setBalancePending(state);
|
|
case TypeKeys.WALLET_SET_BALANCE_FULFILLED:
|
|
return setBalanceFullfilled(state, action);
|
|
case TypeKeys.WALLET_SET_BALANCE_REJECTED:
|
|
return setBalanceRejected(state);
|
|
case TypeKeys.WALLET_SET_TOKEN_BALANCES_PENDING:
|
|
return setTokenBalancesPending(state);
|
|
case TypeKeys.WALLET_SET_TOKEN_BALANCES_FULFILLED:
|
|
return setTokenBalancesFulfilled(state, action);
|
|
case TypeKeys.WALLET_SET_TOKEN_BALANCES_REJECTED:
|
|
return setTokenBalancesRejected(state);
|
|
case TypeKeys.WALLET_SET_TOKEN_BALANCE_PENDING:
|
|
return setTokenBalancePending(state);
|
|
case TypeKeys.WALLET_SET_TOKEN_BALANCE_FULFILLED:
|
|
return setTokenBalanceFufilled(state, action);
|
|
case TypeKeys.WALLET_SET_TOKEN_BALANCE_REJECTED:
|
|
return setTokenBalanceRejected(state);
|
|
case TypeKeys.WALLET_SCAN_WALLET_FOR_TOKENS:
|
|
return scanWalletForTokens(state);
|
|
case TypeKeys.WALLET_SET_WALLET_TOKENS:
|
|
return setWalletTokens(state);
|
|
case TypeKeys.WALLET_SET_CONFIG:
|
|
return setWalletConfig(state, action);
|
|
default:
|
|
return state;
|
|
}
|
|
}
|