@@ -5,17 +5,12 @@ import React, {
55 useMemo ,
66 useState ,
77} from 'react' ;
8- import _ from 'lodash' ;
98import { SigningCyberClient } from '@cybercongress/cyber-js' ;
109import { CYBER } from 'src/utils/config' ;
1110import configKeplr , { getKeplr } from 'src/utils/keplrUtils' ;
1211import { OfflineSigner } from '@cybercongress/cyber-js/build/signingcyberclient' ;
1312import { Option } from 'src/types' ;
14- import { useAppDispatch , useAppSelector } from 'src/redux/hooks' ;
15- import { Keplr } from '@keplr-wallet/types' ;
16- import { addAddressPocket , setDefaultAccount } from 'src/redux/features/pocket' ;
17- import { accountsKeplr } from 'src/utils/utils' ;
18- import usePrevious from 'src/hooks/usePrevious' ;
13+ import { useAppSelector } from 'src/redux/hooks' ;
1914
2015// TODO: interface for keplr and OfflineSigner
2116// type SignerType = OfflineSigner & {
@@ -56,37 +51,11 @@ export function useSigningClient() {
5651}
5752
5853function SigningClientProvider ( { children } : { children : React . ReactNode } ) {
59- const { defaultAccount, accounts } = useAppSelector ( ( state ) => state . pocket ) ;
60- const dispatch = useAppDispatch ( ) ;
54+ const { defaultAccount } = useAppSelector ( ( state ) => state . pocket ) ;
6155 const [ signer , setSigner ] = useState < SignerClientContextType [ 'signer' ] > ( ) ;
6256 const [ signerReady , setSignerReady ] = useState ( false ) ;
6357 const [ signingClient , setSigningClient ] =
6458 useState < SignerClientContextType [ 'signingClient' ] > ( ) ;
65- const prevAccounts = usePrevious ( accounts ) ;
66-
67- const selectAddress = useCallback (
68- async ( keplr : Keplr ) => {
69- if ( ! accounts || _ . isEqual ( prevAccounts , accounts ) ) {
70- return ;
71- }
72- const keyInfo = await keplr . getKey ( CYBER . CHAIN_ID ) ;
73-
74- const findAccount = Object . keys ( accounts ) . find ( ( key ) => {
75- if ( accounts [ key ] . cyber . bech32 === keyInfo . bech32Address ) {
76- return key ;
77- }
78-
79- return undefined ;
80- } ) ;
81-
82- if ( findAccount ) {
83- dispatch ( setDefaultAccount ( { name : findAccount } ) ) ;
84- } else {
85- dispatch ( addAddressPocket ( accountsKeplr ( keyInfo ) ) ) ;
86- }
87- } ,
88- [ accounts , prevAccounts , dispatch ]
89- ) ;
9059
9160 useEffect ( ( ) => {
9261 ( async ( ) => {
@@ -105,8 +74,6 @@ function SigningClientProvider({ children }: { children: React.ReactNode }) {
10574 const initSigner = useCallback ( async ( ) => {
10675 const windowKeplr = await getKeplr ( ) ;
10776 if ( windowKeplr && windowKeplr . experimentalSuggestChain ) {
108- selectAddress ( windowKeplr ) ;
109-
11077 windowKeplr . defaultOptions = {
11178 sign : {
11279 preferNoSetFee : true ,
@@ -125,7 +92,7 @@ function SigningClientProvider({ children }: { children: React.ReactNode }) {
12592 setSigner ( offlineSigner ) ;
12693 setSigningClient ( clientJs ) ;
12794 }
128- } , [ selectAddress ] ) ;
95+ } , [ ] ) ;
12996
13097 useEffect ( ( ) => {
13198 ( async ( ) => {
0 commit comments