Skip to content

Commit

Permalink
Merge branch 'feature/evm' of github.com:DeFiCh/wallet into pierregee…
Browse files Browse the repository at this point in the history
…/test-e2e-runner
  • Loading branch information
lykalabrada committed Oct 19, 2023
2 parents 31e9b77 + ee164ef commit bda790d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import { RefreshIcon } from "@screens/WalletNavigator/assets/RefreshIcon";
import { DomainType, useDomainContext } from "@contexts/DomainContext";
import { RandomAvatar } from "@screens/AppNavigator/screens/Portfolio/components/RandomAvatar";
import { EvmTag } from "@components/EvmTag";
import { useLogger } from "@shared-contexts/NativeLoggingProvider";
import { ButtonGroup } from "../../Dex/components/ButtonGroup";
import {
FavoriteCheckIcon,
Expand All @@ -71,7 +70,6 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
const { network } = useNetworkContext();
const { isEvmFeatureEnabled } = useDomainContext();
const dispatch = useAppDispatch();
const logger = useLogger();
// condition to hide icon if not from send page
const isAddressSelectDisabled =
selectedAddress !== undefined && onAddressSelect !== undefined;
Expand Down Expand Up @@ -128,16 +126,6 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
: ButtonGroupTabKey.Whitelisted,
);

const [availableAddresses, setAvailableAddresses] = useState<
WalletAddressI[]
>([]);

// Getting addresses
const fetchAddresses = async (): Promise<void> => {
const addresses = await fetchWalletAddresses();
setAvailableAddresses(addresses);
};

useEffect(() => {
// combine redux store and jellyfish wallet
let isSubscribed = true;
Expand All @@ -157,7 +145,7 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
addresses.push({
address: address.dvm,
evmAddress: address.evm,
label: "",
label: address.generatedLabel,
});
} else {
addresses.push({
Expand Down Expand Up @@ -196,6 +184,7 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
.includes(searchString?.trim().toLowerCase()) ||
address.address.includes(searchString?.trim().toLowerCase()) ||
address.evmAddress.includes(searchString?.trim().toLowerCase()),
// || (address.label === ""),
) as LocalAddress[],
);
}, 200),
Expand Down Expand Up @@ -248,10 +237,6 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
});
};

useEffect(() => {
fetchAddresses().catch(logger.error);
}, []);

useEffect(() => {
// sync all store changes to local storage
const updateLocalStorage = async (): Promise<void> => {
Expand Down Expand Up @@ -446,13 +431,6 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
}): JSX.Element => {
const { item, index, testIDSuffix } = props;

const generatedAddressLabel = availableAddresses.find(
(address) =>
address.dvm === item.address || address.evm === item.evmAddress,
)?.generatedLabel;
const displayAddressLabel =
item.label === "" ? generatedAddressLabel : item.label;

const onChangeAddress = (addressDetail: string): void => {
if (onAddressSelect) {
onAddressSelect(addressDetail);
Expand Down Expand Up @@ -494,21 +472,12 @@ export function AddressBookScreen({ route, navigation }: Props): JSX.Element {
onPress={onDFIAddressClick}
style={tailwind("flex flex-row items-center")}
>
{item.label !== "" ? (
<ThemedTextV2
style={tailwind("font-semibold-v2 text-sm min-w-0")}
testID={`address_row_label_${index}_${testIDSuffix}`}
>
{item.label}
</ThemedTextV2>
) : (
<ThemedTextV2
style={tailwind("font-semibold-v2 text-sm min-w-0")}
testID={`address_row_label_${index}_${testIDSuffix}`}
>
{displayAddressLabel}
</ThemedTextV2>
)}
<ThemedTextV2
style={tailwind("font-semibold-v2 text-sm min-w-0")}
testID={`address_row_label_${index}_${testIDSuffix}`}
>
{item.label}
</ThemedTextV2>
</TouchableOpacity>
<RandomAvatar name={item.address} size={24} />
</View>
Expand Down
16 changes: 11 additions & 5 deletions shared/contexts/StatsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useAppDispatch } from "@hooks/useAppDispatch";
import { useWhaleApiClient } from "@waveshq/walletkit-ui/dist/contexts";

export function StatsProvider(
props: PropsWithChildren<any>
props: PropsWithChildren<any>,
): JSX.Element | null {
const { network } = useNetworkContext();
const logger = useLogger();
Expand All @@ -24,6 +24,7 @@ export function StatsProvider(
// isPolling is a good indicator of background polling
// we can use AppState to suspend and activate polling based on user activity
let intervalID: NodeJS.Timeout;
let timeoutID: NodeJS.Timeout;

function refresh(): void {
dispatch(block.actions.setPolling(true));
Expand All @@ -38,7 +39,7 @@ export function StatsProvider(
lastSync: new Date().toString(),
lastSuccessfulSync: new Date().toString(),
tvl: tvl?.dex ?? 0,
})
}),
);
dispatch(block.actions.setConnected(true));
})
Expand All @@ -49,22 +50,27 @@ export function StatsProvider(
count: 0,
masternodeCount: 0,
lastSync: new Date().toString(),
})
}),
);
dispatch(block.actions.setConnected(false));
logger.error(err);
});
}

if (!isPolling) {
refresh();
intervalID = setInterval(refresh, interval);
timeoutID = setTimeout(() => {
refresh();
intervalID = setInterval(refresh, interval);
}, 1000);
}
return () => {
dispatch(block.actions.setPolling(false));
if (intervalID !== undefined) {
clearInterval(intervalID);
}
if (timeoutID !== undefined) {
clearTimeout(timeoutID);
}
};
}, [api, interval, network, dispatch]);

Expand Down

0 comments on commit bda790d

Please sign in to comment.