fix: fixed the autoconnect (#355)
This commit is contained in:
parent
223b55bff8
commit
be671efd64
@ -30,22 +30,19 @@ const mapErrorMessages = (providerId: string, errorMessage: string) => {
|
||||
}
|
||||
|
||||
export default function WalletConnecting(props: Props) {
|
||||
const { extensionProviders, recentWallet, connect, simulate, sign, broadcast } = useShuttle()
|
||||
const { recentWallet, connect, simulate, sign, broadcast } = useShuttle()
|
||||
const [isConnecting, setIsConnecting] = useToggle()
|
||||
const providerId = props.providerId ?? recentWallet?.providerId
|
||||
const isAutoConnect = props.autoConnect
|
||||
const client = useStore((s) => s.client)
|
||||
|
||||
const handleConnect = useCallback(
|
||||
(extensionProviderId: string) => {
|
||||
async function handleConnectAsync() {
|
||||
if (client || isConnecting) return
|
||||
setIsConnecting(true)
|
||||
|
||||
try {
|
||||
const provider = extensionProviders.find((p) => p.id === providerId)
|
||||
const response =
|
||||
isAutoConnect && provider
|
||||
? await provider.connect({ chainId: currentChainId })
|
||||
: await connect({ extensionProviderId, chainId: currentChainId })
|
||||
const response = await connect({ extensionProviderId, chainId: currentChainId })
|
||||
const cosmClient = await CosmWasmClient.connect(response.network.rpc)
|
||||
const walletClient: WalletClient = {
|
||||
broadcast,
|
||||
@ -61,8 +58,11 @@ export default function WalletConnecting(props: Props) {
|
||||
focusComponent: { component: <WalletFetchBalancesAndAccounts /> },
|
||||
})
|
||||
} catch (error) {
|
||||
setIsConnecting(false)
|
||||
|
||||
if (isAutoConnect) return
|
||||
|
||||
if (error instanceof Error) {
|
||||
setIsConnecting(false)
|
||||
useStore.setState({
|
||||
client: undefined,
|
||||
address: undefined,
|
||||
@ -81,19 +81,15 @@ export default function WalletConnecting(props: Props) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleConnectAsync()
|
||||
setTimeout(
|
||||
() => {
|
||||
if (isConnecting) return
|
||||
handleConnectAsync()
|
||||
},
|
||||
isAutoConnect ? 1000 : 0,
|
||||
)
|
||||
},
|
||||
[
|
||||
broadcast,
|
||||
connect,
|
||||
extensionProviders,
|
||||
isAutoConnect,
|
||||
providerId,
|
||||
setIsConnecting,
|
||||
sign,
|
||||
simulate,
|
||||
],
|
||||
[broadcast, connect, client, isAutoConnect, isConnecting, setIsConnecting, sign, simulate],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -12,10 +12,10 @@ import {
|
||||
ExecuteMsg as CreditManagerExecuteMsg,
|
||||
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||
import { getSingleValueFromBroadcastResult } from 'utils/broadcast'
|
||||
import { defaultFee } from 'utils/constants'
|
||||
import { formatAmountWithSymbol } from 'utils/formatters'
|
||||
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
||||
import { BN } from 'utils/helpers'
|
||||
import { defaultFee } from 'utils/constants'
|
||||
|
||||
function generateExecutionMessage(
|
||||
sender: string | undefined = '',
|
||||
@ -56,8 +56,11 @@ export default function createBroadcastSlice(
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const getEstimatedFee = async (messages: MsgExecuteContract[]) => {
|
||||
if (!get().client) {
|
||||
console.warn('Client not initialized')
|
||||
return defaultFee
|
||||
}
|
||||
try {
|
||||
const simulateResult = await get().client?.simulate({
|
||||
messages,
|
||||
|
Loading…
Reference in New Issue
Block a user