diff --git a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx index 56e0a4911..03dfb6a17 100644 --- a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx +++ b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx @@ -10,7 +10,6 @@ import { } from '@/services/subsocial/utils/mutation' import { getBalancesQuery } from '@/services/substrateBalances/query' import { useSendEvent } from '@/stores/analytics' -import { useMyAccount } from '@/stores/my-account' import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation' import { SubsocialMutationConfig } from '@/subsocial-query/subsocial/types' import { balanceWithDecimal } from '@subsocial/utils' @@ -100,13 +99,10 @@ const Wrapper = createMutationWrapper( useLockOrIncreaseTx, 'Failed to stake or increase the stake tokens. Please try again.' ) - export const LockOrIncreaseTxWrapper = ({ closeModal, children, }: LockOrIncreaseTxWrapperProps) => { - const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) - return ( { return ( diff --git a/src/components/extensions/donate/DonateModal/donateForm/mutation.tsx b/src/components/extensions/donate/DonateModal/donateForm/mutation.tsx index 1a0c2168c..c9aaa51bd 100644 --- a/src/components/extensions/donate/DonateModal/donateForm/mutation.tsx +++ b/src/components/extensions/donate/DonateModal/donateForm/mutation.tsx @@ -92,5 +92,6 @@ export function useSubstrateDonation( export const SubstrateDonationWrapper = createMutationWrapper( useSubstrateDonation, - 'Failed to donate' + 'Failed to donate', + true ) diff --git a/src/services/api/mutation.ts b/src/services/api/mutation.ts index 705de6b8f..3154e679c 100644 --- a/src/services/api/mutation.ts +++ b/src/services/api/mutation.ts @@ -16,6 +16,7 @@ import mutationWrapper from '@/subsocial-query/base' import { apiInstance } from './utils' export async function requestToken({ address }: ApiRequestTokenBody) { + if (!address) return // make request token as pending transaction so websocket won't disconnect for 10 secs after request token // this is to make energy subscription work const requestTokenId = `request-token-${Date.now()}` diff --git a/src/services/subsocial/hooks.ts b/src/services/subsocial/hooks.ts index 3fde70f06..57cc72cab 100644 --- a/src/services/subsocial/hooks.ts +++ b/src/services/subsocial/hooks.ts @@ -35,13 +35,20 @@ export default function useCommonTxSteps( otherProps?: OtherProps ) => UseMutationResult, config?: SubsocialMutationConfig, + isUsingConnectedWallet?: boolean, otherProps?: OtherProps ) { + const connectedWallet = useMyAccount((state) => state.connectedWallet) + const grillAddress = useMyAccount.use.address() const myAddress = useMyMainAddress() + const address = isUsingConnectedWallet ? connectedWallet?.address : myAddress - const hasEnoughEnergy = useMyAccount((state) => + const hasEnoughEnergyGrillAddress = useMyAccount((state) => getHasEnoughEnergy(state.energy) ) + const hasEnoughEnergy = isUsingConnectedWallet + ? getHasEnoughEnergy(connectedWallet?.energy) + : hasEnoughEnergyGrillAddress const { mutateAsync } = useMutationHook(config, otherProps) const { mutateAsync: requestToken } = useRequestToken() @@ -49,8 +56,8 @@ export default function useCommonTxSteps( const { promptUserForLogin } = useLoginOption() const workerFunc = async (params: Data) => { - let usedAddress: string = myAddress ?? '' - if (!usedAddress) { + let usedAddress: string = address ?? '' + if (!grillAddress) { const address = await promptUserForLogin() if (!address) return usedAddress = address diff --git a/src/services/subsocial/proxy/mutation.ts b/src/services/subsocial/proxy/mutation.ts index 22e53d531..fc48ce8ec 100644 --- a/src/services/subsocial/proxy/mutation.ts +++ b/src/services/subsocial/proxy/mutation.ts @@ -70,7 +70,8 @@ export function useAddProxy(config?: SubsocialMutationConfig) { } export const AddProxyWrapper = createMutationWrapper( useAddProxy, - 'Failed to add proxy' + 'Failed to add proxy', + true ) export function useRemoveProxy(config?: SubsocialMutationConfig) { diff --git a/src/services/subsocial/utils/mutation.tsx b/src/services/subsocial/utils/mutation.tsx index 7bc305b57..0354fd426 100644 --- a/src/services/subsocial/utils/mutation.tsx +++ b/src/services/subsocial/utils/mutation.tsx @@ -16,7 +16,8 @@ export function createMutationWrapper( config?: SubsocialMutationConfig, otherProps?: OtherProps ) => UseMutationResult, - errorMessage: string + errorMessage: string, + isUsingConnectedWallet?: boolean ) { return function MutationWrapper({ children, @@ -65,6 +66,7 @@ export function createMutationWrapper( }, }, }, + isUsingConnectedWallet, otherProps ) useToastError(error, errorMessage)