Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fdf6e39a4 | ||
|
|
563bb8d31a | ||
|
|
6b0a730a2d |
+1
-3
@@ -4,6 +4,4 @@ REACT_APP_DEFAULT_GAS_PRICE=0.025
|
||||
# Reference: https://github.com/cosmos/cosmos-sdk/issues/16020
|
||||
REACT_APP_GAS_ADJUSTMENT=2
|
||||
REACT_APP_LACONICD_RPC_URL=https://laconicd-sapo.laconic.com
|
||||
|
||||
# Example: https://example-url-1.com,https://example-url-2.com
|
||||
REACT_APP_ALLOWED_URLS=
|
||||
REACT_APP_DEPLOY_APP_URL=
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "web-wallet",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.3",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@cerc-io/registry-sdk": "^0.2.5",
|
||||
|
||||
+12
-7
@@ -41,9 +41,8 @@ import { AutoSignIn } from "./screens/AutoSignIn";
|
||||
import { checkSufficientFunds, getPathKey, sendMessage } from "./utils/misc";
|
||||
import useAccountsData from "./hooks/useAccountsData";
|
||||
import { useWebViewHandler } from "./hooks/useWebViewHandler";
|
||||
import SignRequestEmbed from "./screens/SignRequestEmbed";
|
||||
import useAddAccountEmbed from "./hooks/useAddAccountEmbed";
|
||||
import useExportPKEmbed from "./hooks/useExportPrivateKeyEmbed";
|
||||
import SignMessageEmbed from "./screens/SignMessageEmbed";
|
||||
import { AddAccountEmbed } from "./screens/AddAccountEmbed";
|
||||
|
||||
const Stack = createStackNavigator<StackParamsList>();
|
||||
|
||||
@@ -284,8 +283,6 @@ const App = (): React.JSX.Element => {
|
||||
const showWalletConnect = useMemo(() => accounts.length > 0, [accounts]);
|
||||
|
||||
useWebViewHandler();
|
||||
useAddAccountEmbed();
|
||||
useExportPKEmbed();
|
||||
|
||||
return (
|
||||
<Surface style={styles.appSurface}>
|
||||
@@ -396,9 +393,17 @@ const App = (): React.JSX.Element => {
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="sign-request-embed"
|
||||
component={SignRequestEmbed}
|
||||
name="add-account-embed"
|
||||
component={AddAccountEmbed}
|
||||
options={{
|
||||
header: () => <></>,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="sign-message-embed"
|
||||
component={SignMessageEmbed}
|
||||
options={{
|
||||
// eslint-disable-next-line react/no-unstable-nested-components
|
||||
header: () => <Header title="Wallet" />,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Account } from '../types';
|
||||
|
||||
const AccountsContext = createContext<{
|
||||
accounts: Account[];
|
||||
setAccounts: React.Dispatch<React.SetStateAction<Account[]>>;
|
||||
setAccounts: (account: Account[]) => void;
|
||||
currentIndex: number;
|
||||
setCurrentIndex: (index: number) => void;
|
||||
}>({
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useAccounts } from '../context/AccountsContext';
|
||||
import { getPathKey, sendMessage } from '../utils/misc';
|
||||
|
||||
const useExportPKEmbed = () => {
|
||||
const { accounts } = useAccounts();
|
||||
|
||||
useEffect(() => {
|
||||
const handleMessage = async (event: MessageEvent) => {
|
||||
const { type, chainId, address } = event.data;
|
||||
|
||||
if (type !== 'REQUEST_ACCOUNT_PK') return;
|
||||
|
||||
try {
|
||||
const selectedAccount = accounts.find(account => account.address === address);
|
||||
if (!selectedAccount) {
|
||||
throw new Error("Account not found")
|
||||
}
|
||||
|
||||
const pathKey = await getPathKey(chainId, selectedAccount.index);
|
||||
const privateKey = pathKey.privKey;
|
||||
|
||||
sendMessage(
|
||||
event.source as Window,
|
||||
'ACCOUNT_PK_DATA',
|
||||
{ privateKey },
|
||||
event.origin,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error fetching private key:', error);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleMessage);
|
||||
return () => {
|
||||
window.removeEventListener('message', handleMessage);
|
||||
};
|
||||
}, [accounts]);
|
||||
};
|
||||
|
||||
export default useExportPKEmbed;
|
||||
@@ -6,8 +6,6 @@ import useAccountsData from "./useAccountsData";
|
||||
import { useNetworks } from "../context/NetworksContext";
|
||||
import { useAccounts } from "../context/AccountsContext";
|
||||
|
||||
const REACT_APP_ALLOWED_URLS = process.env.REACT_APP_ALLOWED_URLS;
|
||||
|
||||
const useGetOrCreateAccounts = () => {
|
||||
const { networksData } = useNetworks();
|
||||
const { getAccountsData } = useAccountsData();
|
||||
@@ -33,18 +31,6 @@ const useGetOrCreateAccounts = () => {
|
||||
const handleCreateAccounts = async (event: MessageEvent) => {
|
||||
if (event.data.type !== 'REQUEST_CREATE_OR_GET_ACCOUNTS') return;
|
||||
|
||||
if (!REACT_APP_ALLOWED_URLS) {
|
||||
console.log('Allowed URLs are not set');
|
||||
return;
|
||||
}
|
||||
|
||||
const allowedUrls = REACT_APP_ALLOWED_URLS.split(',').map(url => url.trim());
|
||||
|
||||
if (!allowedUrls.includes(event.origin)) {
|
||||
console.log('Unauthorized app.');
|
||||
return;
|
||||
}
|
||||
|
||||
const accountsData = await getOrCreateAccountsForChain(event.data.chainId);
|
||||
|
||||
sendMessage(
|
||||
@@ -56,7 +42,7 @@ const useGetOrCreateAccounts = () => {
|
||||
|
||||
const autoCreateAccounts = async () => {
|
||||
const defaultChainId = networksData[0]?.chainId;
|
||||
|
||||
|
||||
if (!defaultChainId) {
|
||||
console.log('useGetOrCreateAccounts: No default chainId found');
|
||||
return;
|
||||
@@ -74,7 +60,7 @@ const useGetOrCreateAccounts = () => {
|
||||
window.addEventListener('message', handleCreateAccounts);
|
||||
|
||||
const isAndroidWebView = !!(window.Android);
|
||||
|
||||
|
||||
if (isAndroidWebView) {
|
||||
autoCreateAccounts();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export const useWebViewHandler = () => {
|
||||
const path = `/sign/${selectedNetwork.namespace}/${selectedNetwork.chainId}/${currentAccount.address}/${encodeURIComponent(message)}`;
|
||||
const pathRegex = /^\/sign\/(eip155|cosmos)\/(.+)\/(.+)\/(.+)$/;
|
||||
const match = path.match(pathRegex);
|
||||
|
||||
|
||||
if (!match) {
|
||||
window.Android?.onSignatureError?.('Invalid signing path');
|
||||
return;
|
||||
|
||||
@@ -1,39 +1,32 @@
|
||||
import { useEffect, useCallback } from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import { useNetworks } from '../context/NetworksContext';
|
||||
import { sendMessage } from '../utils/misc';
|
||||
import useAccountsData from '../hooks/useAccountsData';
|
||||
import { addAccount } from '../utils/accounts';
|
||||
import useGetOrCreateAccounts from '../hooks/useGetOrCreateAccounts';
|
||||
import { addAccount, retrieveSingleAccount } from '../utils/accounts';
|
||||
import { useAccounts } from '../context/AccountsContext';
|
||||
import { Account, NetworksDataState } from '../types';
|
||||
|
||||
const REACT_APP_ALLOWED_URLS = process.env.REACT_APP_ALLOWED_URLS;
|
||||
|
||||
const useAddAccountEmbed = () => {
|
||||
export const AddAccountEmbed = () => {
|
||||
const { networksData } = useNetworks();
|
||||
const { setAccounts, setCurrentIndex } = useAccounts();
|
||||
const { accounts, setAccounts, setCurrentIndex } =
|
||||
useAccounts();
|
||||
const { getAccountsData } = useAccountsData();
|
||||
|
||||
const addAccountHandler = useCallback(async (network: NetworksDataState) => {
|
||||
const addAccountHandler = async (network: NetworksDataState) => {
|
||||
const newAccount = await addAccount(network);
|
||||
if (newAccount) {
|
||||
setAccounts(prev => [...prev, newAccount]);
|
||||
setAccounts([...accounts, newAccount]);
|
||||
setCurrentIndex(newAccount.index);
|
||||
}
|
||||
}, [setAccounts, setCurrentIndex]);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const handleAddAccount = async (event: MessageEvent) => {
|
||||
if (event.data.type !== 'ADD_ACCOUNT') return;
|
||||
|
||||
if (!REACT_APP_ALLOWED_URLS) {
|
||||
console.log('Unauthorized app origin:', event.origin);
|
||||
return;
|
||||
}
|
||||
|
||||
const allowedUrls = REACT_APP_ALLOWED_URLS.split(',').map(url => url.trim());
|
||||
|
||||
if (!allowedUrls.includes(event.origin)) {
|
||||
if (event.origin !== process.env.REACT_APP_DEPLOY_APP_URL) {
|
||||
console.log('Unauthorized app.');
|
||||
return;
|
||||
}
|
||||
@@ -41,10 +34,10 @@ const useAddAccountEmbed = () => {
|
||||
const network = networksData.find(network => network.chainId === event.data.chainId);
|
||||
|
||||
await addAccountHandler(network!);
|
||||
const updatedAccounts = await getAccountsData(event.data.chainId);
|
||||
const addresses = updatedAccounts.map((account: Account) => account.address);
|
||||
const accounts = await getAccountsData(event.data.chainId);
|
||||
const accountsData: string[] = accounts.map((account: Account) => account.address);
|
||||
|
||||
sendMessage(event.source as Window, 'ADD_ACCOUNT_RESPONSE', addresses, event.origin);
|
||||
sendMessage(event.source as Window, 'ADD_ACCOUNT_RESPONSE', accountsData, event.origin);
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleAddAccount);
|
||||
@@ -52,7 +45,14 @@ const useAddAccountEmbed = () => {
|
||||
return () => {
|
||||
window.removeEventListener('message', handleAddAccount);
|
||||
};
|
||||
}, [networksData, getAccountsData, addAccountHandler]);
|
||||
};
|
||||
}, [networksData, getAccountsData]);
|
||||
|
||||
export default useAddAccountEmbed;
|
||||
// Custom hook for adding listener to get accounts data
|
||||
useGetOrCreateAccounts();
|
||||
|
||||
console.log('wallet')
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
)
|
||||
};
|
||||
@@ -7,8 +7,6 @@ import { sendMessage } from '../utils/misc';
|
||||
import useAccountsData from '../hooks/useAccountsData';
|
||||
import useGetOrCreateAccounts from '../hooks/useGetOrCreateAccounts';
|
||||
|
||||
const REACT_APP_ALLOWED_URLS = process.env.REACT_APP_ALLOWED_URLS;
|
||||
|
||||
export const AutoSignIn = () => {
|
||||
const { networksData } = useNetworks();
|
||||
|
||||
@@ -18,14 +16,7 @@ export const AutoSignIn = () => {
|
||||
const handleSignIn = async (event: MessageEvent) => {
|
||||
if (event.data.type !== 'AUTO_SIGN_IN') return;
|
||||
|
||||
if (!REACT_APP_ALLOWED_URLS) {
|
||||
console.log('Allowed URLs are not set');
|
||||
return;
|
||||
}
|
||||
|
||||
const allowedUrls = REACT_APP_ALLOWED_URLS.split(',').map(url => url.trim());
|
||||
|
||||
if (!allowedUrls.includes(event.origin)) {
|
||||
if (event.origin !== process.env.REACT_APP_DEPLOY_APP_URL) {
|
||||
console.log('Unauthorized app.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { ScrollView, View } from 'react-native';
|
||||
import { ActivityIndicator, Button, Text, Appbar } from 'react-native-paper';
|
||||
|
||||
@@ -16,11 +16,9 @@ import { getCosmosAccounts, retrieveSingleAccount } from '../utils/accounts';
|
||||
import { getMnemonic, getPathKey, sendMessage } from '../utils/misc';
|
||||
import { COSMOS } from '../utils/constants';
|
||||
|
||||
const REACT_APP_ALLOWED_URLS = process.env.REACT_APP_ALLOWED_URLS;
|
||||
type SignRequestProps = NativeStackScreenProps<StackParamsList, 'sign-message-embed'>;
|
||||
|
||||
type SignRequestProps = NativeStackScreenProps<StackParamsList, 'sign-request-embed'>;
|
||||
|
||||
const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
const SignMessageEmbed = ({ route }: SignRequestProps) => {
|
||||
const [displayAccount, setDisplayAccount] = useState<Account>();
|
||||
const [message, setMessage] = useState<string>('');
|
||||
const [chainId, setChainId] = useState<string>('');
|
||||
@@ -72,7 +70,8 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
const rejectRequestHandler = useCallback(async () => {
|
||||
|
||||
const rejectRequestHandler = async () => {
|
||||
if (sourceWindow && origin) {
|
||||
sendMessage(
|
||||
sourceWindow,
|
||||
@@ -81,25 +80,13 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
origin,
|
||||
);
|
||||
}
|
||||
}, [sourceWindow, origin]);
|
||||
navigation.navigate('Home');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const handleCosmosSignMessage = async (event: MessageEvent) => {
|
||||
if (event.data.type !== 'SIGN_ZENITH_MESSAGE') return;
|
||||
|
||||
|
||||
if (!REACT_APP_ALLOWED_URLS) {
|
||||
console.log('Allowed URLs are not set');
|
||||
return;
|
||||
}
|
||||
|
||||
const allowedUrls = REACT_APP_ALLOWED_URLS.split(',').map(url => url.trim());
|
||||
|
||||
if (!allowedUrls.includes(event.origin)) {
|
||||
console.log('Unauthorized app.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { signerAddress, signDoc } = event.data.params;
|
||||
|
||||
@@ -115,7 +102,7 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
event.data.chainId,
|
||||
signerAddress,
|
||||
);
|
||||
|
||||
|
||||
setDisplayAccount(requestAccount);
|
||||
setIsLoading(false);
|
||||
} catch (err) {
|
||||
@@ -149,7 +136,8 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
);
|
||||
},
|
||||
});
|
||||
}, [navigation, rejectRequestHandler]);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [navigation, route.name]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -186,4 +174,4 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default SignRequestEmbed;
|
||||
export default SignMessageEmbed;
|
||||
+2
-1
@@ -40,7 +40,8 @@ export type StackParamsList = {
|
||||
};
|
||||
"wallet-embed": undefined;
|
||||
"auto-sign-in": undefined;
|
||||
"sign-request-embed": undefined;
|
||||
"sign-message-embed": undefined;
|
||||
"add-account-embed": undefined;
|
||||
};
|
||||
|
||||
export type Account = {
|
||||
|
||||
@@ -22,7 +22,7 @@ export const DEFAULT_NETWORKS: NetworksFormData[] = [
|
||||
chainId: 'zenith-testnet',
|
||||
networkName: 'zenithd testnet',
|
||||
namespace: COSMOS,
|
||||
rpcUrl: 'https://zenith-node-rpc.com',
|
||||
rpcUrl: 'http://127.0.0.1:26657',
|
||||
blockExplorerUrl: '',
|
||||
nativeDenom: 'znt',
|
||||
addressPrefix: 'zenith',
|
||||
|
||||
@@ -10,7 +10,7 @@ services:
|
||||
CERC_DEFAULT_GAS_PRICE: ${CERC_DEFAULT_GAS_PRICE:-0.025}
|
||||
CERC_GAS_ADJUSTMENT: ${CERC_GAS_ADJUSTMENT:-2}
|
||||
CERC_LACONICD_RPC_URL: ${CERC_LACONICD_RPC_URL:-https://laconicd.laconic.com}
|
||||
CERC_ALLOWED_URLS: ${CERC_ALLOWED_URLS}
|
||||
CERC_DEPLOY_APP_URL: ${CERC_DEPLOY_APP_URL}
|
||||
command: ["bash", "/scripts/run.sh"]
|
||||
volumes:
|
||||
- ../config/app/run.sh:/scripts/run.sh
|
||||
|
||||
@@ -10,14 +10,14 @@ echo "WALLET_CONNECT_ID: ${WALLET_CONNECT_ID}"
|
||||
echo "CERC_DEFAULT_GAS_PRICE: ${CERC_DEFAULT_GAS_PRICE}"
|
||||
echo "CERC_GAS_ADJUSTMENT: ${CERC_GAS_ADJUSTMENT}"
|
||||
echo "CERC_LACONICD_RPC_URL: ${CERC_LACONICD_RPC_URL}"
|
||||
echo "CERC_ALLOWED_URLS: ${CERC_ALLOWED_URLS}"
|
||||
echo "CERC_DEPLOY_APP_URL: ${CERC_DEPLOY_APP_URL}"
|
||||
|
||||
# Build with required env
|
||||
REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_ID \
|
||||
REACT_APP_DEFAULT_GAS_PRICE=$CERC_DEFAULT_GAS_PRICE \
|
||||
REACT_APP_GAS_ADJUSTMENT=$CERC_GAS_ADJUSTMENT \
|
||||
REACT_APP_LACONICD_RPC_URL=$CERC_LACONICD_RPC_URL \
|
||||
REACT_APP_ALLOWED_URLS=$CERC_ALLOWED_URLS \
|
||||
REACT_APP_DEPLOY_APP_URL=$CERC_DEPLOY_APP_URL \
|
||||
yarn build
|
||||
|
||||
# Define the directory and file path
|
||||
|
||||
@@ -49,9 +49,6 @@ Instructions for running the `laconic-wallet-web` using [laconic-so](https://git
|
||||
# WalletConnect project ID, same should be used in the laconic-wallet
|
||||
WALLET_CONNECT_ID=
|
||||
|
||||
# Allowed urls is a comma separated list of allowed urls
|
||||
CERC_ALLOWED_URLS=
|
||||
|
||||
# Optional
|
||||
|
||||
# WalletConnect code for hostname verification
|
||||
@@ -66,6 +63,10 @@ Instructions for running the `laconic-wallet-web` using [laconic-so](https://git
|
||||
|
||||
# RPC endpoint of laconicd node (default: https://laconicd.laconic.com)
|
||||
CERC_LACONICD_RPC_URL=
|
||||
|
||||
# Deploy app URL used for checking origin of the messages for auto-sign-in route
|
||||
# Deploy app repo: https://git.vdb.to/cerc-io/snowballtools-base
|
||||
CERC_DEPLOY_APP_URL=
|
||||
```
|
||||
|
||||
## Start the deployment
|
||||
|
||||
Reference in New Issue
Block a user