From 6b760a6d3008d34aec3d7a5dbb1d0e2ab5c078b0 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 30 May 2024 23:31:34 +0700 Subject: [PATCH 1/5] Revert "Merge pull request #669 from dappforce/deploy/fix-wallet" This reverts commit ff64dfe09aae781d79af86702fc5c62ba98b1de9, reversing changes made to bcd08c61c9a6950162e64569499f396878749c1b. --- .../content-staking/mutations/lockOrIncreaseTx.tsx | 11 ++++++----- .../content-staking/mutations/unlockTx.tsx | 13 ++++++++----- .../content-staking/mutations/withdraw.tsx | 14 +++++++++----- .../donate/DonateModal/donateForm/mutation.tsx | 3 ++- src/services/subsocial/hooks.ts | 12 +++++++++--- src/services/subsocial/proxy/mutation.ts | 3 ++- src/services/subsocial/utils/mutation.tsx | 4 +++- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx index 56e0a4911..5957c18d7 100644 --- a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx +++ b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx @@ -96,17 +96,18 @@ type LockOrIncreaseTxWrapperProps = { }) => JSX.Element } -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) + const Wrapper = createMutationWrapper( + useLockOrIncreaseTx, + 'Failed to stake or increase the stake tokens. Please try again.', + !!parentProxyAddress + ) + return ( JSX.Element } -const Wrapper = createMutationWrapper( - useUnlockTx, - 'Failed to unlock the tokens' -) - export const UnlockTxWrapper = ({ closeModal, children, }: UnlockTxWrapperProps) => { + const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) + + const Wrapper = createMutationWrapper( + useUnlockTx, + 'Failed to unlock the tokens', + !!parentProxyAddress + ) + return ( JSX.Element } -const Wrapper = createMutationWrapper( - useWithdrawTx, - 'Failed to withdraw unlocked tokens. Please try again.' -) - export const WithdrawTxWrapper = ({ children }: WithdrawTxWrapperProps) => { + const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) + + const Wrapper = createMutationWrapper( + useWithdrawTx, + 'Failed to withdraw unlocked tokens. Please try again.', + !!parentProxyAddress + ) + return ( {(props) => { 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/subsocial/hooks.ts b/src/services/subsocial/hooks.ts index 3fde70f06..711ae496e 100644 --- a/src/services/subsocial/hooks.ts +++ b/src/services/subsocial/hooks.ts @@ -35,13 +35,19 @@ export default function useCommonTxSteps( otherProps?: OtherProps ) => UseMutationResult, config?: SubsocialMutationConfig, + isUsingConnectedWallet?: boolean, otherProps?: OtherProps ) { + const connectedWallet = useMyAccount((state) => state.connectedWallet) 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 +55,8 @@ export default function useCommonTxSteps( const { promptUserForLogin } = useLoginOption() const workerFunc = async (params: Data) => { - let usedAddress: string = myAddress ?? '' - if (!usedAddress) { + let usedAddress: string = address ?? '' + if (!address) { 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) From 60ffc112b8ec5ade4d1d1f285cfb6b6982d6ca4d Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 30 May 2024 23:40:09 +0700 Subject: [PATCH 2/5] Fix issue with polkadot login with accounts without energy is not working --- .../PolkadotConnectConfirmationContent.tsx | 2 ++ .../content-staking/mutations/unlockTx.tsx | 13 ++++++++----- .../content-staking/mutations/withdraw.tsx | 13 ++++++++----- src/services/subsocial/hooks.ts | 4 +++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx b/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx index 17601d6a9..3aec834f2 100644 --- a/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx +++ b/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx @@ -44,6 +44,8 @@ export default function PolkadotConnectConfirmationContent({ { enabled: !!connectedWallet?.address } ) + console.log(hasEnoughEnergy) + return (
diff --git a/src/components/content-staking/mutations/unlockTx.tsx b/src/components/content-staking/mutations/unlockTx.tsx index 469b712eb..aee38dd5c 100644 --- a/src/components/content-staking/mutations/unlockTx.tsx +++ b/src/components/content-staking/mutations/unlockTx.tsx @@ -21,6 +21,7 @@ import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation' import { SubsocialMutationConfig } from '@/subsocial-query/subsocial/types' import { balanceWithDecimal, isDef } from '@subsocial/utils' import { useQueryClient } from '@tanstack/react-query' +import { useMemo } from 'react' import { useGetMyCreatorsIds } from '../hooks/useGetMyCreatorsIds' import { ACTIVE_STAKING_SPACE_ID } from '../utils' @@ -207,11 +208,13 @@ export const UnlockTxWrapper = ({ }: UnlockTxWrapperProps) => { const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) - const Wrapper = createMutationWrapper( - useUnlockTx, - 'Failed to unlock the tokens', - !!parentProxyAddress - ) + const Wrapper = useMemo(() => { + return createMutationWrapper( + useUnlockTx, + 'Failed to unlock the tokens', + !!parentProxyAddress + ) + }, [parentProxyAddress]) return ( ) { const client = useQueryClient() @@ -56,11 +57,13 @@ type WithdrawTxWrapperProps = { export const WithdrawTxWrapper = ({ children }: WithdrawTxWrapperProps) => { const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) - const Wrapper = createMutationWrapper( - useWithdrawTx, - 'Failed to withdraw unlocked tokens. Please try again.', - !!parentProxyAddress - ) + const Wrapper = useMemo(() => { + return createMutationWrapper( + useWithdrawTx, + 'Failed to withdraw unlocked tokens. Please try again.', + !!parentProxyAddress + ) + }, [parentProxyAddress]) return ( diff --git a/src/services/subsocial/hooks.ts b/src/services/subsocial/hooks.ts index 711ae496e..27f1a790c 100644 --- a/src/services/subsocial/hooks.ts +++ b/src/services/subsocial/hooks.ts @@ -39,6 +39,7 @@ export default function useCommonTxSteps( otherProps?: OtherProps ) { const connectedWallet = useMyAccount((state) => state.connectedWallet) + const grillAddress = useMyAccount.use.address() const myAddress = useMyMainAddress() const address = isUsingConnectedWallet ? connectedWallet?.address : myAddress @@ -56,11 +57,12 @@ export default function useCommonTxSteps( const workerFunc = async (params: Data) => { let usedAddress: string = address ?? '' - if (!address) { + if (!grillAddress) { const address = await promptUserForLogin() if (!address) return usedAddress = address } + console.log(usedAddress, hasEnoughEnergy) if (!hasEnoughEnergy) { const [_, res] = await Promise.all([ From 9b43561b69dd7f0cf776c9661c8b0bc6f7659245 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 30 May 2024 23:40:31 +0700 Subject: [PATCH 3/5] Remove logs --- .../polkadot-connect/PolkadotConnectConfirmationContent.tsx | 2 -- src/services/subsocial/hooks.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx b/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx index 3aec834f2..17601d6a9 100644 --- a/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx +++ b/src/components/auth/common/polkadot-connect/PolkadotConnectConfirmationContent.tsx @@ -44,8 +44,6 @@ export default function PolkadotConnectConfirmationContent({ { enabled: !!connectedWallet?.address } ) - console.log(hasEnoughEnergy) - return (
diff --git a/src/services/subsocial/hooks.ts b/src/services/subsocial/hooks.ts index 27f1a790c..57cc72cab 100644 --- a/src/services/subsocial/hooks.ts +++ b/src/services/subsocial/hooks.ts @@ -62,7 +62,6 @@ export default function useCommonTxSteps( if (!address) return usedAddress = address } - console.log(usedAddress, hasEnoughEnergy) if (!hasEnoughEnergy) { const [_, res] = await Promise.all([ From 1c9763b8d787ba8847b2a5fb4d8c1cb01450318d Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 30 May 2024 23:41:47 +0700 Subject: [PATCH 4/5] Add use memo --- .../content-staking/mutations/lockOrIncreaseTx.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx index 5957c18d7..2cb0c4b73 100644 --- a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx +++ b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx @@ -15,6 +15,7 @@ import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation' import { SubsocialMutationConfig } from '@/subsocial-query/subsocial/types' import { balanceWithDecimal } from '@subsocial/utils' import { useQueryClient } from '@tanstack/react-query' +import { useMemo } from 'react' import getAmountRange from '../utils/getAmountRangeForAnalytics' type MutationProps = { @@ -102,11 +103,13 @@ export const LockOrIncreaseTxWrapper = ({ }: LockOrIncreaseTxWrapperProps) => { const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) - const Wrapper = createMutationWrapper( - useLockOrIncreaseTx, - 'Failed to stake or increase the stake tokens. Please try again.', - !!parentProxyAddress - ) + const Wrapper = useMemo(() => { + return createMutationWrapper( + useLockOrIncreaseTx, + 'Failed to stake or increase the stake tokens. Please try again.', + !!parentProxyAddress + ) + }, [parentProxyAddress]) return ( Date: Fri, 31 May 2024 00:07:20 +0700 Subject: [PATCH 5/5] Fix issue where lock increase don't work --- .../mutations/lockOrIncreaseTx.tsx | 16 ++++------------ .../content-staking/mutations/unlockTx.tsx | 15 ++++----------- .../content-staking/mutations/withdraw.tsx | 16 ++++------------ src/services/api/mutation.ts | 1 + 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx index 2cb0c4b73..03dfb6a17 100644 --- a/src/components/content-staking/mutations/lockOrIncreaseTx.tsx +++ b/src/components/content-staking/mutations/lockOrIncreaseTx.tsx @@ -10,12 +10,10 @@ 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' import { useQueryClient } from '@tanstack/react-query' -import { useMemo } from 'react' import getAmountRange from '../utils/getAmountRangeForAnalytics' type MutationProps = { @@ -97,20 +95,14 @@ type LockOrIncreaseTxWrapperProps = { }) => JSX.Element } +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) - - const Wrapper = useMemo(() => { - return createMutationWrapper( - useLockOrIncreaseTx, - 'Failed to stake or increase the stake tokens. Please try again.', - !!parentProxyAddress - ) - }, [parentProxyAddress]) - return ( JSX.Element } +const Wrapper = createMutationWrapper( + useUnlockTx, + 'Failed to unlock the tokens' +) export const UnlockTxWrapper = ({ closeModal, children, }: UnlockTxWrapperProps) => { - const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) - - const Wrapper = useMemo(() => { - return createMutationWrapper( - useUnlockTx, - 'Failed to unlock the tokens', - !!parentProxyAddress - ) - }, [parentProxyAddress]) - return ( ) { const client = useQueryClient() @@ -54,17 +52,11 @@ type WithdrawTxWrapperProps = { }) => JSX.Element } +const Wrapper = createMutationWrapper( + useWithdrawTx, + 'Failed to withdraw unlocked tokens. Please try again.' +) export const WithdrawTxWrapper = ({ children }: WithdrawTxWrapperProps) => { - const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress) - - const Wrapper = useMemo(() => { - return createMutationWrapper( - useWithdrawTx, - 'Failed to withdraw unlocked tokens. Please try again.', - !!parentProxyAddress - ) - }, [parentProxyAddress]) - return ( {(props) => { 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()}`