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] import wallet selector and chain refactor #433

Merged
merged 1 commit into from
Oct 5, 2022
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
2 changes: 1 addition & 1 deletion src/navigation/tabs/contacts/screens/ContactsAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const ContactsAdd = ({
chain?: string,
) => {
if (address) {
const coinAndNetwork = GetCoinAndNetwork(address);
const coinAndNetwork = GetCoinAndNetwork(address, undefined, chain);
if (coinAndNetwork) {
const isValid = ValidateCoinAddress(
address,
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/wallet/components/MultipleOutputsTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const MultipleOutputsTx = ({tx}: {tx: any}) => {
tx.outputs.forEach((output: any) => {
const outputAddr = output.toAddress ? output.toAddress : output.address;
if (!coin || !network) {
const coinAndNetwork = GetCoinAndNetwork(outputAddr, network);
const coinAndNetwork = GetCoinAndNetwork(outputAddr, network, chain);
coin = coin || coinAndNetwork?.coin;
network = network || coinAndNetwork?.network;
}
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/wallet/components/RecoveryPhrase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ const RecoveryPhrase = () => {
({item}) => {
const currencySelected = (id: string) => {
const _selectedCurrency = CurrencyOptions.filter(
currency => currency.id === id,
currency => currency.currencyAbbreviation === id,
);
const currencyAbbreviation = _selectedCurrency[0].currencyAbbreviation;
const defaultCoin = `default${currencyAbbreviation.toUpperCase()}`;
Expand Down Expand Up @@ -708,7 +708,7 @@ const RecoveryPhrase = () => {
<Row style={{alignItems: 'center'}}>
<CurrencyImage img={selectedCurrency.img} size={30} />
<CurrencyName>
{selectedCurrency?.currencyAbbreviation}
{selectedCurrency?.currencyAbbreviation?.toUpperCase()}
</CurrencyName>
</Row>
<Icons.DownToggle />
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/wallet/components/SendToAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const SendToAddress = () => {
const checkCoinAndNetwork =
(data: any): Effect<boolean> =>
dispatch => {
const addrData = GetCoinAndNetwork(data, network);
const addrData = GetCoinAndNetwork(data, network, chain);
const isValid =
chain === addrData?.coin.toLowerCase() && addrData?.network === network;

Expand Down
9 changes: 6 additions & 3 deletions src/navigation/wallet/screens/AddWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ const AddWallet: React.FC<AddWalletScreenProps> = ({navigation, route}) => {
({id}) => id === associatedWallet.id,
)!;
const {network, currencyAbbreviation, chain} = fullWalletObj;
const addrData = GetCoinAndNetwork(tokenAddress, network);
const addrData = GetCoinAndNetwork(tokenAddress, network, chain);
const isValid =
currencyAbbreviation.toLowerCase() === addrData?.coin.toLowerCase() &&
addrData?.network === network;
network === addrData?.network;

if (!isValid) {
return;
Expand Down Expand Up @@ -494,7 +494,10 @@ const AddWallet: React.FC<AddWalletScreenProps> = ({navigation, route}) => {
<Row
style={{alignItems: 'center', justifyContent: 'space-between'}}>
<Row style={{alignItems: 'center'}}>
<CurrencyImage img={CurrencyListIcons.eth} size={30} />
<CurrencyImage
img={CurrencyListIcons[associatedWallet.chain]}
size={30}
/>
<AssociateWalletName>
{associatedWallet?.walletName ||
`${associatedWallet.currencyAbbreviation.toUpperCase()} Wallet`}
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/wallet/screens/send/SendTo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ const SendTo = () => {
data?.chain?.toLowerCase() === chain.toLowerCase() &&
data?.network.toLowerCase() === network.toLowerCase();
} else {
addrData = GetCoinAndNetwork(data, network);
addrData = GetCoinAndNetwork(data, network, chain);
isValid =
chain === addrData?.coin.toLowerCase() &&
addrData?.network === network;
network === addrData?.network;
}

if (isValid) {
Expand Down
5 changes: 3 additions & 2 deletions src/store/wallet/effects/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const GetAddressNetwork = (address: string, coin: keyof BitcoreLibs) => {
export const GetCoinAndNetwork = (
str: string,
network: string = 'livenet',
evmChain?: string,
): CoinNetwork | null => {
const address = ExtractCoinNetworkAddress(str);
try {
Expand All @@ -144,12 +145,12 @@ export const GetCoinAndNetwork = (
} catch (bchErr) {
try {
const isValidEthAddress = Core.Validation.validateAddress(
'ETH',
evmChain?.toUpperCase() || 'ETH',
network,
address,
);
if (isValidEthAddress) {
return {coin: 'eth', network};
return {coin: evmChain?.toLowerCase() || 'eth', network};
} else {
throw isValidEthAddress;
}
Expand Down
5 changes: 2 additions & 3 deletions src/store/wallet/effects/rates/rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import moment from 'moment';
import {addAltCurrencyList} from '../../../app/app.actions';
import {AltCurrenciesRowProps} from '../../../../components/list/AltCurrenciesRow';
import {LogActions} from '../../../log';
import {BitpaySupportedEthereumTokenOptsByAddress} from '../../../../constants/tokens';
import {BitpaySupportedTokenOptsByAddress} from '../../../../constants/tokens';
import {
getCurrencyAbbreviation,
addTokenChainSuffix,
Expand Down Expand Up @@ -218,7 +218,7 @@ export const getTokenRates =
} = getState();

const tokensOptsByAddress = {
...BitpaySupportedEthereumTokenOptsByAddress,
...BitpaySupportedTokenOptsByAddress,
...tokenOptionsByAddress,
...customTokenOptionsByAddress,
};
Expand All @@ -240,7 +240,6 @@ export const getTokenRates =
)}&vs_currencies=${altCurrencies.join(
',',
)}&include_24hr_change=true&include_last_updated_at=true`;

dispatch(LogActions.debug(`getTokenRates: get request to: ${url}`));
const {data} = await axios.get(url);
dispatch(LogActions.debug('getTokenRates: success get request'));
Expand Down