Allow incoming signature requests from intents (#32)

* Add url scheme and linking

* Pass account to sign request page

* Provide functionality for accepting or rejecting requests

* Load account state before handling url

* Refactor code

* Make intent work when app is cleared from recents

* Fix bug to populate data from intents

* Fix bug to update data on subsequent requests

* Pass correct network to sign messages from cosmos account

* Fix bug to populate data for incoming intent

* Allow spaces in url

* Bad signature page

* Review changes

* Change page heading

* Use correct regex

* Clean up code

* Use https in url

* Set state properly

---------

Co-authored-by: Adw8 <adwait@deepstacksoft.com>
This commit is contained in:
Adwait Gharpure
2024-02-28 19:37:26 +05:30
committed by GitHub
co-authored by adwait
parent fc034356a1
commit 7db0edce75
9 changed files with 280 additions and 14 deletions
+43 -4
View File
@@ -38,10 +38,12 @@ const createWallet = async (): Promise<WalletDetails> => {
const cosmosAddress = (await getCosmosAccounts(mnemonic, "0'/0/0")).data
.address;
const ethAccountInfo = `${"0'/0/0"},${ethNode.privateKey},${ethNode.publicKey
},${ethAddress}`;
const cosmosAccountInfo = `${"0'/0/0"},${cosmosNode.privateKey},${cosmosNode.publicKey
},${cosmosAddress}`;
const ethAccountInfo = `${"0'/0/0"},${ethNode.privateKey},${
ethNode.publicKey
},${ethAddress}`;
const cosmosAccountInfo = `${"0'/0/0"},${cosmosNode.privateKey},${
cosmosNode.publicKey
},${cosmosAddress}`;
await Promise.all([
setInternetCredentials(
@@ -184,6 +186,42 @@ const retrieveAccounts = async (): Promise<{
return { ethLoadedAccounts, cosmosLoadedAccounts };
};
const retrieveSingleAccount = async (network: string, address: string) => {
let loadedAccounts;
switch (network) {
case 'eth':
const ethServer = await getInternetCredentials('eth:globalCounter');
const ethCounter = ethServer && ethServer.password;
if (ethCounter) {
loadedAccounts = await retrieveAccountsForNetwork(network, ethCounter);
}
break;
case 'cosmos':
const cosmosServer = await getInternetCredentials('cosmos:globalCounter');
const cosmosCounter = cosmosServer && cosmosServer.password;
if (cosmosCounter) {
loadedAccounts = await retrieveAccountsForNetwork(
network,
cosmosCounter,
);
}
break;
default:
break;
}
if (loadedAccounts) {
return loadedAccounts.find(account => account.address === address);
}
return undefined;
};
const resetWallet = async () => {
try {
await Promise.all([
@@ -206,5 +244,6 @@ export {
addAccount,
addAccountFromHDPath,
retrieveAccounts,
retrieveSingleAccount,
resetWallet,
};