Skip to content

Commit

Permalink
(NOBIDS) Adding validators with the new API (#387)
Browse files Browse the repository at this point in the history
* (BIDS-2959) making the search-bar communicate with the API with the last specs

* add new search infos to change validators call

* remove count from search body

* param is called group_id

* group_id is now an int

---------

Co-authored-by: Alexander Maushammer <[email protected]>
  • Loading branch information
thib-wien and MauserBitfly authored Jun 6, 2024
1 parent dfd6dac commit a26cdd1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 31 deletions.
3 changes: 1 addition & 2 deletions frontend/components/bc/searchbar/SearchbarMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ async function callAPIthenOrganizeResultsThenCallBack (nonceWhenCalled: number)
body: {
input: userInputText.value,
networks,
types,
include_validators: areResultsCountable(types, true)
types
}
})
} catch (error) {
Expand Down
46 changes: 34 additions & 12 deletions frontend/components/dashboard/ValidatorManagementModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ const selected = ref<VDBManageValidatorsTableRow[]>()
const searchBar = ref<SearchBar>()
const hasNoOpenDialogs = ref(true)
type ValidatorUpdateBody = {
validators?: string[],
deposit_address?: string,
withdrawal_address?: string,
graffiti?: string,
group_id?: number
}
const size = computed(() => {
return {
expandable: width.value < 1060,
Expand Down Expand Up @@ -70,14 +78,14 @@ const mapIndexOrPubKey = (validators?: VDBManageValidatorsTableRow[]): string[]
return uniq(validators?.map(vali => vali.index?.toString() ?? vali.public_key) ?? [])
}
const changeGroup = async (validators?: string[], groupId?: number) => {
if (!validators?.length) {
const changeGroup = async (body: ValidatorUpdateBody, groupId?: number) => {
if (!body.validators?.length && !body.deposit_address && !body.graffiti && !body.withdrawal_address) {
warn('no validators selected to change group')
return
}
const targetGroupId = groupId !== -1 ? groupId?.toString() : '0'
body.group_id = groupId && groupId !== -1 ? groupId : 0
await fetch<VDBPostValidatorsData>(API_PATH.DASHBOARD_VALIDATOR_MANAGEMENT, { method: 'POST', body: { validators, group_id: targetGroupId } }, { dashboardKey: dashboardKey.value })
await fetch<VDBPostValidatorsData>(API_PATH.DASHBOARD_VALIDATOR_MANAGEMENT, { method: 'POST', body }, { dashboardKey: dashboardKey.value })
loadData()
refreshOverview(dashboardKey.value)
Expand All @@ -104,21 +112,35 @@ const addValidator = (result: ResultSuggestion) => {
dialog.open(BcPremiumModal, {})
return
}
let list: string[]
let list: string[] = []
selectedValidator.value = ''
const body: ValidatorUpdateBody = {}
switch (result.type) {
case ResultType.ValidatorsByIndex:
case ResultType.ValidatorsByPubkey:
list = [String(result.rawResult.num_value!)]
selectedValidator.value = String(list[0])
selectedValidator.value = list[0]
body.validators = list
break
case ResultType.ValidatorsByDepositAddress :
case ResultType.ValidatorsByDepositEnsName :
body.deposit_address = result.rawResult.hash_value
break
case ResultType.ValidatorsByWithdrawalCredential :
case ResultType.ValidatorsByWithdrawalAddress :
case ResultType.ValidatorsByWithdrawalEnsName :
body.withdrawal_address = result.rawResult.hash_value
break
case ResultType.ValidatorsByGraffiti :
body.graffiti = result.rawResult.str_value
break
default:
list = result.rawResult.validators!.map(index => String(index))
selectedValidator.value = ''
}
if (isPublic.value || !isLoggedIn.value) {
addEntities(list)
} else {
changeGroup(list, selectedGroup.value)
changeGroup(body, selectedGroup.value)
}
searchBar.value!.empty()
}
Expand All @@ -129,7 +151,7 @@ const editSelected = () => {
onClose: (response) => {
hasNoOpenDialogs.value = true
if (response?.data !== undefined) {
changeGroup(mapIndexOrPubKey(selected.value), response?.data)
changeGroup({ validators: mapIndexOrPubKey(selected.value) }, response?.data)
}
},
data: {
Expand Down Expand Up @@ -184,7 +206,7 @@ watch(() => [dashboardKey.value, visible.value, query.value], () => {
}, { immediate: true })
const switchValidatorGroup = (row: VDBManageValidatorsTableRow, group: number) => {
changeGroup(mapIndexOrPubKey([row].concat(selected.value ?? [])), group)
changeGroup({ validators: mapIndexOrPubKey([row].concat(selected.value ?? [])) }, group)
}
const removeRow = (row: VDBManageValidatorsTableRow) => {
Expand Down
14 changes: 7 additions & 7 deletions frontend/types/searchbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 6,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRhash_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.deposited_by', 0], lowLevelData: Indirect.SASRhash_value }
},
Expand All @@ -414,7 +414,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 5,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRstr_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.deposited_by', 0], lowLevelData: Indirect.SASRstr_value }
},
Expand All @@ -424,7 +424,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 8,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRhash_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.credential', SINGULAR], lowLevelData: Indirect.SASRhash_value }
},
Expand All @@ -434,7 +434,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 8,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRhash_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.withdrawn_to', 0], lowLevelData: Indirect.SASRhash_value }
},
Expand All @@ -444,7 +444,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 7,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRstr_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.withdrawn_to', 0], lowLevelData: Indirect.SASRstr_value }
},
Expand All @@ -454,7 +454,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 9999,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRstr_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.block_graffiti', 0], lowLevelData: Indirect.SASRstr_value }
}
Expand All @@ -464,7 +464,7 @@ export const TypeInfo: Record<ResultType, TypeInfoFields> = {
subCategory: SubCategory.Validators,
priority: 9999,
belongsToAllNetworks: false,
countSource: 'validators',
countSource: 'num_value',
queryParamField: Indirect.SASRstr_value,
howToFillresultSuggestionOutput: { name: Indirect.SubCategoryTitle, description: ['search_bar.named', 0], lowLevelData: Indirect.SASRstr_value }
} */
Expand Down
29 changes: 19 additions & 10 deletions frontend/utils/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function simulateAPIresponseForTheSearchBar (body? : Record<string, any>)
const searched = body?.input as string
const searchableTypes = body?.types as ResultType[]
const searchableNetworks = body?.networks as number[]
const countIdenticalValidators = body?.include_validators as boolean
const countIdenticalValidators = body?.count as boolean
const response : SearchAheadAPIresponse = {} as SearchAheadAPIresponse
response.data = []

Expand Down Expand Up @@ -87,7 +87,8 @@ export function simulateAPIresponseForTheSearchBar (body? : Record<string, any>)
{
chain_id: 1,
type: 'validators_by_deposit_ens_name',
str_value: searched + 'kETH-hodler-club.eth'
str_value: searched + 'kETH-hodler-club.eth',
hash_value: '0x3bfCb296F2d28FaDE20a7E53A508F73557Ca938'
},
{
chain_id: 1,
Expand Down Expand Up @@ -118,7 +119,8 @@ export function simulateAPIresponseForTheSearchBar (body? : Record<string, any>)
{
chain_id: 1,
type: 'validators_by_withdrawal_ens_name',
str_value: searched + '.bitfly.eth'
str_value: searched + '.bitfly.eth',
hash_value: '0xEB84C94dCBBceF74bf6CEB74Bc9bBf418939202D'
},
{
chain_id: 1,
Expand Down Expand Up @@ -285,12 +287,14 @@ export function simulateAPIresponseForTheSearchBar (body? : Record<string, any>)
{
chain_id: 100,
type: 'validators_by_withdrawal_ens_name',
str_value: searched + '-futureoffinance.eth'
str_value: searched + '-futureoffinance.eth',
hash_value: '0x0701BF988309bf45a6771afaa6B8802Ba3E24090'
},
{
chain_id: 100,
type: 'validators_by_withdrawal_ens_name',
str_value: searched + '.bitfly.eth'
str_value: searched + '.bitfly.eth',
hash_value: '0xEB84C94dCBBceF74bf6CEB74Bc9bBf418939202D'
}
)
}
Expand All @@ -305,11 +309,16 @@ export function simulateAPIresponseForTheSearchBar (body? : Record<string, any>)
// adding fake numbers of identical results where it is possible
if (countIdenticalValidators) {
for (const singleRes of response.data) {
if (TypeInfo[singleRes.type as ResultType].countSource) {
const size = 2 + Math.floor(50 * Math.random())
singleRes.validators = [] as number[]
for (let v = 0; v < size; v++) {
singleRes.validators.push(Math.floor(1400000 * Math.random()))
const whereToWrite = TypeInfo[singleRes.type as ResultType].countSource
if (whereToWrite) {
const size = 2 + Math.floor(30 * Math.random())
if (Array.isArray(singleRes[whereToWrite])) {
(singleRes[whereToWrite] as number[]) = []
for (let v = 0; v < size; v++) {
(singleRes[whereToWrite] as number[]).push(Math.floor(1400000 * Math.random()))
}
} else {
(singleRes[whereToWrite] as number) = size
}
}
}
Expand Down

0 comments on commit a26cdd1

Please sign in to comment.