Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Login with polkadot wallet without energy #673

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/components/content-staking/mutations/lockOrIncreaseTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 (
<Wrapper
loadingUntilTxSuccess
Expand Down
1 change: 0 additions & 1 deletion src/components/content-staking/mutations/unlockTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ const Wrapper = createMutationWrapper(
useUnlockTx,
'Failed to unlock the tokens'
)

export const UnlockTxWrapper = ({
closeModal,
children,
Expand Down
1 change: 0 additions & 1 deletion src/components/content-staking/mutations/withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const Wrapper = createMutationWrapper(
useWithdrawTx,
'Failed to withdraw unlocked tokens. Please try again.'
)

export const WithdrawTxWrapper = ({ children }: WithdrawTxWrapperProps) => {
return (
<Wrapper loadingUntilTxSuccess>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ export function useSubstrateDonation(

export const SubstrateDonationWrapper = createMutationWrapper(
useSubstrateDonation,
'Failed to donate'
'Failed to donate',
true
)
1 change: 1 addition & 0 deletions src/services/api/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`
Expand Down
13 changes: 10 additions & 3 deletions src/services/subsocial/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,29 @@ export default function useCommonTxSteps<Data, ReturnValue, OtherProps>(
otherProps?: OtherProps
) => UseMutationResult<ReturnValue, Error, Data, unknown>,
config?: SubsocialMutationConfig<Data>,
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()

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
Expand Down
3 changes: 2 additions & 1 deletion src/services/subsocial/proxy/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export function useAddProxy(config?: SubsocialMutationConfig<null>) {
}
export const AddProxyWrapper = createMutationWrapper(
useAddProxy,
'Failed to add proxy'
'Failed to add proxy',
true
)

export function useRemoveProxy(config?: SubsocialMutationConfig<null>) {
Expand Down
4 changes: 3 additions & 1 deletion src/services/subsocial/utils/mutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function createMutationWrapper<Data, ReturnValue, OtherProps>(
config?: SubsocialMutationConfig<Data, any>,
otherProps?: OtherProps
) => UseMutationResult<ReturnValue, Error, Data, unknown>,
errorMessage: string
errorMessage: string,
isUsingConnectedWallet?: boolean
) {
return function MutationWrapper({
children,
Expand Down Expand Up @@ -65,6 +66,7 @@ export function createMutationWrapper<Data, ReturnValue, OtherProps>(
},
},
},
isUsingConnectedWallet,
otherProps
)
useToastError(error, errorMessage)
Expand Down
Loading