Use constants for event types
This commit is contained in:
parent
96cb0a8051
commit
7e8d7e63e5
@ -45,7 +45,7 @@ import SignRequestEmbed from "./screens/SignRequestEmbed";
|
||||
import useAddAccountEmbed from "./hooks/useAddAccountEmbed";
|
||||
import useExportPKEmbed from "./hooks/useExportPrivateKeyEmbed";
|
||||
import { SignTxEmbed } from "./screens/SignTxEmbed";
|
||||
import useGetOrCreateNetwork from "./hooks/useGetOrNetworkAccounts";
|
||||
import useCreateNetwork from "./hooks/useGetOrNetworkAccounts";
|
||||
|
||||
const Stack = createStackNavigator<StackParamsList>();
|
||||
|
||||
@ -288,7 +288,7 @@ const App = (): React.JSX.Element => {
|
||||
useWebViewHandler();
|
||||
useAddAccountEmbed();
|
||||
useExportPKEmbed();
|
||||
useGetOrCreateNetwork();
|
||||
useCreateNetwork();
|
||||
|
||||
return (
|
||||
<Surface style={styles.appSurface}>
|
||||
|
||||
@ -2,13 +2,13 @@ import { useEffect, useCallback } from "react";
|
||||
|
||||
import { addAccountsForNetwork, addNewNetwork, createWallet, getNextAccountId, isChainIdPresent, isWalletCreated } from "../utils/accounts";
|
||||
import { useNetworks } from "../context/NetworksContext";
|
||||
import { REQUEST_ADD_NETWORK } from "../utils/constants";
|
||||
import { NETWORK_ADD_FAILED, NETWORK_ADDED_SUCCESSFULLY, NETWORK_ALREADY_EXISTS, REQUEST_ADD_NETWORK } from "../utils/constants";
|
||||
import { NetworksFormData } from "../types";
|
||||
import { sendMessage } from "../utils/misc";
|
||||
|
||||
const REACT_APP_ALLOWED_URLS = import.meta.env.REACT_APP_ALLOWED_URLS;
|
||||
|
||||
const useGetOrCreateNetwork = () => {
|
||||
const useCreateNetwork = () => {
|
||||
const { networksData, setNetworksData } = useNetworks();
|
||||
|
||||
const getOrCreateNetwork = useCallback(
|
||||
@ -31,8 +31,8 @@ const useGetOrCreateNetwork = () => {
|
||||
if (chainId !== networkData.chainId) {
|
||||
console.log("Network data not available.");
|
||||
if (sourceOrigin) {
|
||||
sendMessage(window.parent, "NETWORK_ADD_FAILED", {
|
||||
type: "NETWORK_ADD_FAILED",
|
||||
sendMessage(window.parent, NETWORK_ADD_FAILED, {
|
||||
type: NETWORK_ADD_FAILED,
|
||||
message: "Invalid or missing network data"
|
||||
}, sourceOrigin);
|
||||
}
|
||||
@ -69,20 +69,20 @@ const useGetOrCreateNetwork = () => {
|
||||
|
||||
await addAccountsForNetwork(selectedNetwork!, nextAccountId - 1);
|
||||
|
||||
sendMessage(window.parent, "NETWORK_ADDED_SUCCESSFULLY", {
|
||||
type: "NETWORK_ADDED_SUCCESSFULLY",
|
||||
sendMessage(window.parent, NETWORK_ADDED_SUCCESSFULLY, {
|
||||
type: NETWORK_ADDED_SUCCESSFULLY,
|
||||
chainId
|
||||
}, sourceOrigin);
|
||||
} else {
|
||||
sendMessage(window.parent, "NETWORK_ALREADY_EXISTS", {
|
||||
type: "NETWORK_ALREADY_EXISTS",
|
||||
sendMessage(window.parent, NETWORK_ALREADY_EXISTS, {
|
||||
type: NETWORK_ALREADY_EXISTS,
|
||||
chainId
|
||||
}, sourceOrigin);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error in getOrCreateNetwork:", error);
|
||||
sendMessage(window.parent, "NETWORK_ADD_FAILED", {
|
||||
type: "NETWORK_ADD_FAILED",
|
||||
sendMessage(window.parent, NETWORK_ADD_FAILED, {
|
||||
type: NETWORK_ADD_FAILED,
|
||||
message: error instanceof Error ? error.message : "Unknown error"
|
||||
}, sourceOrigin);
|
||||
}
|
||||
@ -118,4 +118,4 @@ const useGetOrCreateNetwork = () => {
|
||||
}, [getOrCreateNetwork]);
|
||||
};
|
||||
|
||||
export default useGetOrCreateNetwork;
|
||||
export default useCreateNetwork;
|
||||
|
||||
@ -99,6 +99,9 @@ export const REQUEST_ADD_ACCOUNT = 'REQUEST_ADD_ACCOUNT';
|
||||
export const AUTO_SIGN_IN = 'AUTO_SIGN_IN';
|
||||
export const CHECK_BALANCE = 'CHECK_BALANCE';
|
||||
export const REQUEST_ADD_NETWORK = 'REQUEST_ADD_NETWORK';
|
||||
export const NETWORK_ADD_FAILED = "NETWORK_ADD_FAILED";
|
||||
export const NETWORK_ADDED_SUCCESSFULLY = "NETWORK_ADDED_SUCCESSFULLY";
|
||||
export const NETWORK_ALREADY_EXISTS = "NETWORK_ALREADY_EXISTS";
|
||||
|
||||
// iframe response types
|
||||
export const COSMOS_ACCOUNTS_RESPONSE = 'COSMOS_ACCOUNTS_RESPONSE';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user