Compare commits

..
7 changed files with 26 additions and 10 deletions
+1
View File
@@ -0,0 +1 @@
build
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "web-wallet",
"version": "0.1.2",
"version": "0.1.3",
"private": true,
"dependencies": {
"@cerc-io/registry-sdk": "^0.2.5",
+2 -4
View File
@@ -58,10 +58,8 @@ const NetworksProvider = ({ children }: { children: React.ReactNode }) => {
setSelectedNetwork(retrievedNetworks[0]);
};
if (networksData.length === 0) {
fetchData();
}
}, [networksData]);
fetchData();
}, []);
useEffect(() => {
setSelectedNetwork(prevSelectedNetwork => {
+6 -2
View File
@@ -23,7 +23,11 @@ const useGetOrCreateAccounts = () => {
accountsData = await getAccountsData(event.data.chainId);
}
sendMessage(event.source as Window, 'WALLET_ACCOUNTS_DATA', accountsData, event.origin);
sendMessage(
event.source as Window, 'WALLET_ACCOUNTS_DATA',
accountsData.map(account => account.address),
event.origin
);
};
window.addEventListener('message', handleCreateAccounts);
@@ -31,7 +35,7 @@ const useGetOrCreateAccounts = () => {
return () => {
window.removeEventListener('message', handleCreateAccounts);
};
}, [networksData, getAccountsData ]);
}, [networksData, getAccountsData]);
};
export default useGetOrCreateAccounts;
+1
View File
@@ -88,6 +88,7 @@ export const WalletEmbed = () => {
throw new Error('Requested network not supported.');
}
console.log({ network, fromAddress, chainId, toAddress, amount });
const account = await retrieveSingleAccount(network.namespace, network.chainId, fromAddress);
if (!account) {
throw new Error('Account not found for the requested address.');
+6 -2
View File
@@ -3,6 +3,7 @@ For more information, "visit https://docs.ethers.org/v5/cookbook/react-native/#c
import 'react-native-get-random-values';
import '@ethersproject/shims';
import { fromBech32 } from '@cosmjs/encoding';
import { Wallet } from 'ethers';
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
@@ -24,7 +25,7 @@ const signMessage = async ({
case EIP155:
return await signEthMessage(message, accountId, chainId);
case COSMOS:
return await signCosmosMessage(message, path.path);
return await signCosmosMessage(message, path.path, path.address);
default:
throw new Error('Invalid wallet type');
}
@@ -51,10 +52,13 @@ const signEthMessage = async (
const signCosmosMessage = async (
message: string,
path: string,
cosmosAddress: string,
): Promise<string | undefined> => {
try {
const mnemonic = await getMnemonic();
const cosmosAccount = await getCosmosAccounts(mnemonic, path);
const addressPrefix = fromBech32(cosmosAddress).prefix
const cosmosAccount = await getCosmosAccounts(mnemonic, path, addressPrefix);
const address = cosmosAccount.data.address;
const cosmosSignature = await cosmosAccount.cosmosWallet.signAmino(
address,
@@ -9,6 +9,7 @@ import {
StdFee,
MsgSendEncodeObject
} from '@cosmjs/stargate';
import { fromBech32 } from '@cosmjs/encoding';
import { EncodeObject } from '@cosmjs/proto-signing';
import { LaconicClient } from '@cerc-io/registry-sdk';
import { Buffer } from 'buffer';
@@ -19,6 +20,7 @@ import { Account } from '../../types';
import { getMnemonic, getPathKey } from '../misc';
import { getCosmosAccounts } from '../accounts';
import { COSMOS_METHODS } from './COSMOSData';
import { COSMOS } from '../constants';
interface EthSendTransaction {
type: 'eth_sendTransaction';
@@ -80,7 +82,13 @@ export async function approveWalletConnectRequest(
const path = (await getPathKey(`${namespace}:${chainId}`, account.index))
.path;
const mnemonic = await getMnemonic();
const cosmosAccount = await getCosmosAccounts(mnemonic, path);
let addressPrefix: string | undefined
if (namespace === COSMOS) {
addressPrefix = fromBech32(account.address).prefix
}
const cosmosAccount = await getCosmosAccounts(mnemonic, path, addressPrefix);
const address = account.address;
switch (request.method) {