Skip to content

Commit

Permalink
Refactor Follow component to use write function
Browse files Browse the repository at this point in the history
  • Loading branch information
sasicodes committed Jan 23, 2024
1 parent c23aa1e commit c296c4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
23 changes: 11 additions & 12 deletions apps/web/src/components/Profile/BasicInfo/Follow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ const Follow: FC<Props> = ({ profile, onSubscribe }) => {
}
})

const write = ({ args }: { args: any[] }) => {
return writeContract({
address: LENSHUB_PROXY_ADDRESS,
abi: LENSHUB_PROXY_ABI,
functionName: 'follow',
args
})
}

const [broadcast] = useBroadcastOnchainMutation({
onCompleted: ({ broadcastOnchain }) =>
onCompleted(broadcastOnchain.__typename),
Expand Down Expand Up @@ -101,21 +110,11 @@ const Follow: FC<Props> = ({ profile, onSubscribe }) => {
variables: { request: { id, signature } }
})
if (data?.broadcastOnchain?.__typename === 'RelayError') {
return writeContract({
address: LENSHUB_PROXY_ADDRESS,
abi: LENSHUB_PROXY_ABI,
functionName: 'follow',
args
})
return write({ args })
}
return
}
return writeContract({
address: LENSHUB_PROXY_ADDRESS,
abi: LENSHUB_PROXY_ABI,
functionName: 'follow',
args
})
return write({ args })
} catch {
setLoading(false)
}
Expand Down
23 changes: 11 additions & 12 deletions apps/web/src/components/Profile/BasicInfo/SuperFollow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ const SuperFollow: FC<Props> = ({ profile, onJoin }) => {
onError
})

const write = ({ args }: { args: any[] }) => {
return writeContract({
address: LENSHUB_PROXY_ADDRESS,
abi: LENSHUB_PROXY_ABI,
functionName: 'follow',
args
})
}

const { data: followModuleData } = useProfileFollowModuleQuery({
variables: { request: { forProfileId: profile?.id } },
skip: !profile?.id
Expand Down Expand Up @@ -155,21 +164,11 @@ const SuperFollow: FC<Props> = ({ profile, onJoin }) => {
variables: { request: { id, signature } }
})
if (data?.broadcastOnchain.__typename === 'RelayError') {
return writeContract({
address: LENSHUB_PROXY_ADDRESS,
abi: LENSHUB_PROXY_ABI,
functionName: 'follow',
args
})
return write({ args })
}
return
}
return writeContract({
address: LENSHUB_PROXY_ADDRESS,
abi: LENSHUB_PROXY_ABI,
functionName: 'follow',
args
})
return write({ args })
} catch {
setLoading(false)
}
Expand Down

0 comments on commit c296c4b

Please sign in to comment.