Use /api/v1/settings/move_followers endpoint to move followers
This commit is contained in:
parent
f1cd206a39
commit
2be8e2baa0
5 changed files with 31 additions and 47 deletions
|
@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
- Added "Experiments" section to Settings page (includes "Move Followers" feature).
|
- Added "Experiments" section to Settings page (includes "Move Followers" feature).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Use `/api/v1/settings/move_followers` endpoint to move followers.
|
||||||
|
|
||||||
## [1.9.0] - 2023-01-08
|
## [1.9.0] - 2023-01-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -48,3 +48,22 @@ export async function exportFollows(
|
||||||
const blob = await response.blob()
|
const blob = await response.blob()
|
||||||
downloadBlob(blob)
|
downloadBlob(blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function moveFollowers(
|
||||||
|
authToken: string,
|
||||||
|
fromActorId: string,
|
||||||
|
followersCsv: string,
|
||||||
|
): Promise<User> {
|
||||||
|
const url = `${BACKEND_URL}/api/v1/settings/move_followers`
|
||||||
|
const response = await http(url, {
|
||||||
|
method: "POST",
|
||||||
|
authToken,
|
||||||
|
json: { from_actor_id: fromActorId, followers_csv: followersCsv },
|
||||||
|
})
|
||||||
|
const data = await response.json()
|
||||||
|
if (response.status !== 200) {
|
||||||
|
throw new Error(data.message)
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -267,25 +267,6 @@ interface UnsignedActivity {
|
||||||
message: string,
|
message: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUnsignedMove(
|
|
||||||
authToken: string,
|
|
||||||
fromActorId: string,
|
|
||||||
followersCsv: string,
|
|
||||||
): Promise<UnsignedActivity> {
|
|
||||||
const url = `${BACKEND_URL}/api/v1/accounts/move_followers`
|
|
||||||
const response = await http(url, {
|
|
||||||
method: "POST",
|
|
||||||
authToken,
|
|
||||||
json: { from_actor_id: fromActorId, followers_csv: followersCsv },
|
|
||||||
})
|
|
||||||
const data = await response.json()
|
|
||||||
if (response.status !== 200) {
|
|
||||||
throw new Error(data.message)
|
|
||||||
} else {
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getUnsignedUpdate(
|
export async function getUnsignedUpdate(
|
||||||
authToken: string,
|
authToken: string,
|
||||||
): Promise<UnsignedActivity> {
|
): Promise<UnsignedActivity> {
|
||||||
|
|
|
@ -1,33 +1,10 @@
|
||||||
import {
|
import {
|
||||||
getUnsignedMove,
|
|
||||||
getUnsignedUpdate,
|
getUnsignedUpdate,
|
||||||
sendSignedActivity,
|
sendSignedActivity,
|
||||||
} from "@/api/users"
|
} from "@/api/users"
|
||||||
import { useCurrentUser } from "@/store/user"
|
import { useCurrentUser } from "@/store/user"
|
||||||
import { getWallet, getWalletSignature } from "@/utils/ethereum"
|
import { getWallet, getWalletSignature } from "@/utils/ethereum"
|
||||||
|
|
||||||
async function signMoveActivity(fromActorId: string, followersCsv: string) {
|
|
||||||
const { ensureAuthToken } = useCurrentUser()
|
|
||||||
const signer = await getWallet()
|
|
||||||
if (!signer) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const walletAddress = await signer.getAddress()
|
|
||||||
const authToken = ensureAuthToken()
|
|
||||||
const { params, message } = await getUnsignedMove(
|
|
||||||
authToken,
|
|
||||||
fromActorId,
|
|
||||||
followersCsv,
|
|
||||||
)
|
|
||||||
const signature = await getWalletSignature(signer, message)
|
|
||||||
await sendSignedActivity(
|
|
||||||
authToken,
|
|
||||||
params,
|
|
||||||
walletAddress,
|
|
||||||
signature,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function signUpdateActivity(): Promise<void> {
|
async function signUpdateActivity(): Promise<void> {
|
||||||
const { ensureAuthToken } = useCurrentUser()
|
const { ensureAuthToken } = useCurrentUser()
|
||||||
if (!confirm("This action will sign a message with your wallet and send it to your followers. Continue?")) {
|
if (!confirm("This action will sign a message with your wallet and send it to your followers. Continue?")) {
|
||||||
|
@ -51,7 +28,6 @@ async function signUpdateActivity(): Promise<void> {
|
||||||
|
|
||||||
export function useSignedActivity() {
|
export function useSignedActivity() {
|
||||||
return {
|
return {
|
||||||
signMoveActivity,
|
|
||||||
signUpdateActivity,
|
signUpdateActivity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,12 @@
|
||||||
import { $, $ref } from "vue/macros"
|
import { $, $ref } from "vue/macros"
|
||||||
import { useRouter } from "vue-router"
|
import { useRouter } from "vue-router"
|
||||||
|
|
||||||
|
import { moveFollowers } from "@/api/settings"
|
||||||
import SidebarLayout from "@/components/SidebarLayout.vue"
|
import SidebarLayout from "@/components/SidebarLayout.vue"
|
||||||
import { useSignedActivity } from "@/composables/signed-activity"
|
|
||||||
import { useCurrentUser } from "@/store/user"
|
import { useCurrentUser } from "@/store/user"
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { currentUser } = $(useCurrentUser())
|
const { currentUser, ensureAuthToken, setCurrentUser } = $(useCurrentUser())
|
||||||
const { signMoveActivity } = useSignedActivity()
|
|
||||||
|
|
||||||
const fromActorId = $ref("")
|
const fromActorId = $ref("")
|
||||||
const followersCsv = $ref("")
|
const followersCsv = $ref("")
|
||||||
|
@ -55,7 +54,12 @@ async function move() {
|
||||||
if (currentUser === null) {
|
if (currentUser === null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await signMoveActivity(fromActorId, followersCsv)
|
const user = await moveFollowers(
|
||||||
|
ensureAuthToken(),
|
||||||
|
fromActorId,
|
||||||
|
followersCsv,
|
||||||
|
)
|
||||||
|
setCurrentUser(user)
|
||||||
router.push({ name: "profile", params: { profileId: currentUser.id } })
|
router.push({ name: "profile", params: { profileId: currentUser.id } })
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue