Update sign message request handler
This commit is contained in:
parent
8d49dfbe90
commit
6af4e7224e
@ -30,7 +30,7 @@ import { getSignParamsMessage } from "./utils/wallet-connect/helpers";
|
||||
import ApproveTransfer from "./screens/ApproveTransfer";
|
||||
import AddNetwork from "./screens/AddNetwork";
|
||||
import EditNetwork from "./screens/EditNetwork";
|
||||
import { COSMOS, EIP155 } from "./utils/constants";
|
||||
import { CHECK_BALANCE, COSMOS, EIP155, IS_SUFFICIENT } from "./utils/constants";
|
||||
import { useNetworks } from "./context/NetworksContext";
|
||||
import { NETWORK_METHODS } from "./utils/wallet-connect/common-data";
|
||||
import { COSMOS_METHODS } from "./utils/wallet-connect/COSMOSData";
|
||||
@ -232,7 +232,7 @@ const App = (): React.JSX.Element => {
|
||||
|
||||
useEffect(() => {
|
||||
const handleCheckBalance = async (event: MessageEvent) => {
|
||||
if (event.data.type !== 'CHECK_BALANCE') return;
|
||||
if (event.data.type !== CHECK_BALANCE) return;
|
||||
|
||||
const { chainId, amount } = event.data;
|
||||
const network = networksData.find(net => net.chainId === chainId);
|
||||
@ -272,7 +272,7 @@ const App = (): React.JSX.Element => {
|
||||
|
||||
const areFundsSufficient = checkSufficientFunds(amount, balance.amount);
|
||||
|
||||
sendMessage(event.source as Window, 'IS_SUFFICIENT', areFundsSufficient, event.origin);
|
||||
sendMessage(event.source as Window, IS_SUFFICIENT, areFundsSufficient, event.origin);
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleCheckBalance);
|
||||
|
||||
@ -25,6 +25,7 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
const [displayAccount, setDisplayAccount] = useState<Account>();
|
||||
const [message, setMessage] = useState<string>('');
|
||||
const [chainId, setChainId] = useState<string>('');
|
||||
const [namespace, setNamespace] = useState<string>('');
|
||||
const [signDoc, setSignDoc] = useState<any>(null);
|
||||
const [signerAddress, setSignerAddress] = useState<string>('');
|
||||
const [origin, setOrigin] = useState<string>('');
|
||||
@ -41,8 +42,13 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
|
||||
setIsApproving(true);
|
||||
try {
|
||||
const requestAccount = await retrieveSingleAccount(COSMOS, chainId, signerAddress);
|
||||
const path = (await getPathKey(`${COSMOS}:${chainId}`, requestAccount!.index)).path;
|
||||
if (namespace !== COSMOS) {
|
||||
// TODO: Support ETH namespace
|
||||
throw new Error(`namespace ${namespace} is not supported`)
|
||||
}
|
||||
|
||||
const requestAccount = await retrieveSingleAccount(namespace, chainId, signerAddress);
|
||||
const path = (await getPathKey(`${namespace}:${chainId}`, requestAccount!.index)).path;
|
||||
const mnemonic = await getMnemonic();
|
||||
|
||||
const requestedNetworkData = networksData.find(networkData => networkData.chainId === chainId)
|
||||
@ -111,16 +117,25 @@ const SignRequestEmbed = ({ route }: SignRequestProps) => {
|
||||
try {
|
||||
const { signerAddress, signDoc } = event.data.params;
|
||||
|
||||
const receivedNamespace = event.data.chainId.split(':')[0]
|
||||
const receivedChainId = event.data.chainId.split(':')[1]
|
||||
|
||||
if (receivedNamespace !== COSMOS) {
|
||||
// TODO: Support ETH namespace
|
||||
throw new Error(`namespace ${receivedNamespace} is not supported`)
|
||||
}
|
||||
|
||||
setSignerAddress(signerAddress);
|
||||
setSignDoc(signDoc);
|
||||
setMessage(signDoc.memo || '');
|
||||
setOrigin(event.origin);
|
||||
setSourceWindow(event.source as Window);
|
||||
setChainId(event.data.chainId);
|
||||
setNamespace(receivedNamespace);
|
||||
setChainId(receivedChainId);
|
||||
|
||||
const requestAccount = await retrieveSingleAccount(
|
||||
COSMOS,
|
||||
event.data.chainId,
|
||||
receivedNamespace,
|
||||
receivedChainId,
|
||||
signerAddress,
|
||||
);
|
||||
|
||||
|
||||
@ -82,9 +82,10 @@ export const REQUEST_SIGN_MESSAGE = 'REQUEST_SIGN_MESSAGE';
|
||||
export const REQUEST_WALLET_ACCOUNTS = 'REQUEST_WALLET_ACCOUNTS';
|
||||
export const REQUEST_CREATE_OR_GET_ACCOUNTS = 'REQUEST_CREATE_OR_GET_ACCOUNTS';
|
||||
export const REQUEST_TX = 'REQUEST_TX';
|
||||
export const AUTO_SIGN_IN = 'AUTO_SIGN_IN';
|
||||
export const REQUEST_ACCOUNT_PK = 'REQUEST_ACCOUNT_PK';
|
||||
export const REQUEST_ADD_ACCOUNT = 'ADD_ACCOUNT';
|
||||
export const AUTO_SIGN_IN = 'AUTO_SIGN_IN';
|
||||
export const CHECK_BALANCE = 'CHECK_BALANCE';
|
||||
|
||||
// iframe response types
|
||||
export const COSMOS_ACCOUNTS_RESPONSE = 'COSMOS_ACCOUNTS_RESPONSE';
|
||||
@ -95,3 +96,4 @@ export const SIGN_IN_RESPONSE = 'SIGN_IN_RESPONSE';
|
||||
export const ACCOUNT_PK_RESPONSE = 'ACCOUNT_PK_RESPONSE';
|
||||
export const ADD_ACCOUNT_RESPONSE = 'ADD_ACCOUNT_RESPONSE';
|
||||
export const WALLET_ACCOUNTS_DATA = 'WALLET_ACCOUNTS_DATA';
|
||||
export const IS_SUFFICIENT = 'IS_SUFFICIENT';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user