forked from cerc-io/laconic-wallet
Use context for maintaining accounts state (#41)
* Use context for maintaining accounts state * Remove custom hook from context
This commit is contained in:
@@ -7,15 +7,18 @@ import { getSdkError } from '@walletconnect/utils';
|
||||
import { EIP155_SIGNING_METHODS } from './EIP155Lib';
|
||||
import { getSignParamsMessage, getAccountNumberFromParams } from './Helpers';
|
||||
import { signEthMessage } from '../sign-message';
|
||||
import { Account } from '../../types';
|
||||
|
||||
export async function approveEIP155Request(
|
||||
requestEvent: SignClientTypes.EventArguments['session_request'],
|
||||
currentEthAddresses: string[],
|
||||
ethAccounts: Account[],
|
||||
) {
|
||||
const { params, id } = requestEvent;
|
||||
const { request } = params;
|
||||
const counterId = await getAccountNumberFromParams(
|
||||
currentEthAddresses,
|
||||
ethAccounts,
|
||||
params,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Taken from https://medium.com/walletconnect/how-to-build-a-wallet-in-react-native-with-the-web3wallet-sdk-b6f57bf02f9a
|
||||
|
||||
import { retrieveAccounts } from '../accounts';
|
||||
import { EIP155_CHAINS, TEIP155Chain } from './EIP155Lib';
|
||||
import { utils } from 'ethers';
|
||||
|
||||
import { Account } from '../../types';
|
||||
import { EIP155_CHAINS, TEIP155Chain } from './EIP155Lib';
|
||||
|
||||
/**
|
||||
* Truncates string (in the middle) via given lenght value
|
||||
*/
|
||||
@@ -67,6 +68,7 @@ export function getSignTypedDataParamsData(params: string[]) {
|
||||
*/
|
||||
export async function getAccountNumberFromParams(
|
||||
addresses: string[],
|
||||
ethAccounts: Account[],
|
||||
params: any,
|
||||
) {
|
||||
const paramsString = JSON.stringify(params);
|
||||
@@ -78,9 +80,7 @@ export async function getAccountNumberFromParams(
|
||||
}
|
||||
});
|
||||
|
||||
const { ethLoadedAccounts } = await retrieveAccounts();
|
||||
|
||||
const currentAccount = ethLoadedAccounts!.find(
|
||||
const currentAccount = ethAccounts!.find(
|
||||
account => account.address === address,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user