Skip to content

Commit

Permalink
Add support for Delegate Registry v2 (#4492)
Browse files Browse the repository at this point in the history
* feat: set form.to as delegate address

* feat-wip: initial split delegation UI updates to SpaceDelegatesDelegateModal

* choir: Adds addDelegate, deleteDelegate, deleteAllDelegates functions

* wip: updates divide equally and cleans up definition

* feat: add delegates logic for Delegate Row Form

* Updates clear all delegates logic

* Updates x button hover

* Refactor the delegation setup to be agnostic to how the data fetching and setting happens

* Add delegate registry v2 reading

* Add delegate registry v2 balance

* Make it possible to view delegateRegistryV2 delegates

* Activate the delegates sidebar link for delegate registry v2 delegations

* Fix prettier problems

* [delegate registry v2]Add offset/skip to delegat query

* Add separate delegation UI for different delegation types

* Update DELEGATE_REGISTRY_BACKEND_URL

* feat: Connect the logic for setting the delegation

* Update weight calculation in handleConfirm function

* Add expiration time to setDelegates function and get it from the Modal

* WIP: Adds Expiration field

* feat: implement expiration date logic

* chore: clean code

* chore: remove unnecessary  variables

* Default expiration time to one year in the future + Some refactoring

* chore: Apply PR comments

* fix: adjust file imports

* fix orderBy filter

* format units to default to 18 decimals

* bug: remove wrong percentage format

* add number of delegators to read

* use new api structure

* fix object key reference

* fix units

* add fetch method

* rename registry v2 -> split delegation

* adjust for api changes

* cleanup split delegation modal

* fix address ordering

* fix sub-strategy param on fetch

* update read.ts to new api schema

* use delegators from new api schema

* update api request body to match new schema

* use strategy set backendUrl if available

* PR fixups

* display current delegations in modal

* add error if weights are over 100

* switch to using delegatePortal settings where appropriate

* adds ability to clear all delegations

* chore: file renaming

* refactor: centralize delegation portal enabling

* refactor: DRY-ing modal definition

* refactor: remove redundant import

* refactor: modify ref inside same function for more readability

* refactor: remove redundant return

* refactor: follow coding style for error arg name

* refactor: remove uneeded ref

* fix: remove unused function

* feat: set form.to as delegate address

* feat-wip: initial split delegation UI updates to SpaceDelegatesDelegateModal

* choir: Adds addDelegate, deleteDelegate, deleteAllDelegates functions

* wip: updates divide equally and cleans up definition

* feat: add delegates logic for Delegate Row Form

* Updates clear all delegates logic

* Updates x button hover

* Refactor the delegation setup to be agnostic to how the data fetching and setting happens

* Add delegate registry v2 reading

* Add delegate registry v2 balance

* Make it possible to view delegateRegistryV2 delegates

* Activate the delegates sidebar link for delegate registry v2 delegations

* Fix prettier problems

* [delegate registry v2]Add offset/skip to delegat query

* Add separate delegation UI for different delegation types

* Update DELEGATE_REGISTRY_BACKEND_URL

* feat: Connect the logic for setting the delegation

* Update weight calculation in handleConfirm function

* Add expiration time to setDelegates function and get it from the Modal

* WIP: Adds Expiration field

* feat: implement expiration date logic

* chore: clean code

* chore: remove unnecessary  variables

* Default expiration time to one year in the future + Some refactoring

* chore: Apply PR comments

* fix: adjust file imports

* fix orderBy filter

* format units to default to 18 decimals

* bug: remove wrong percentage format

* add number of delegators to read

* use new api structure

* fix object key reference

* fix units

* add fetch method

* rename registry v2 -> split delegation

* adjust for api changes

* cleanup split delegation modal

* fix address ordering

* fix sub-strategy param on fetch

* update read.ts to new api schema

* use delegators from new api schema

* update api request body to match new schema

* use strategy set backendUrl if available

* PR fixups

* display current delegations in modal

* add error if weights are over 100

* switch to using delegatePortal settings where appropriate

* adds ability to clear all delegations

* refactor: rename file to follow convention

* chore: revert back changes to .env

* chore: remove redundant file

* fix: use property from composable to check valid delegation portal

* refactor: refactor to follow coding style

* refactor: refactor to follow coding style

* refactor: removed uneeded variable

* fix: show notification error on tx building error

* fix: only use `hasDelegationPortal` from composable to check for delegation validity

* fix: fix invalid variable type

* fix: fix delegate statement not loading

* fix: fix content flashing

* fix: fix event triggering on page quit

* fix: do not return undefined delegation

* add sender to delegations when power < 100, clarify language

* fix: handle floats when equally distributing power

* fix: hide self delegate button on split delegation

* fix(ui): delegate form should start with a blank delegate field

* fix: add min and max to weight

* fix: ensure all addresses are unique

* fix: fix missing translation text

* refactor: code standard

* fix: remove empty string from duplicate addresses comparison

* fix: remove unused ref

* chore: remove leftover code from copy/paste

* fix: UI fix

* remove unused function, notify on wrong network

* fix: refresh delegatingTo properly on account change

* fix: fix wrong comparison

---------

Co-authored-by: juliopavila <[email protected]>
Co-authored-by: Colin Spence <[email protected]>
Co-authored-by: samepant <[email protected]>
Co-authored-by: samepant <[email protected]>
Co-authored-by: Wan Qi Chen <[email protected]>
  • Loading branch information
6 people authored Jul 4, 2024
1 parent c820500 commit bddda20
Show file tree
Hide file tree
Showing 25 changed files with 1,248 additions and 398 deletions.
3 changes: 3 additions & 0 deletions src/components/BaseSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const props = defineProps<{
placeholder?: string;
modal?: boolean;
focusOnMount?: boolean;
isDisabled?: boolean;
}>();
const emit = defineEmits(['update:modelValue']);
Expand Down Expand Up @@ -49,6 +50,8 @@ watch(
autocorrect="off"
autocapitalize="none"
class="input w-full border-none"
:class="{ '!cursor-not-allowed': isDisabled }"
:disabled="isDisabled"
@input="handleInput"
/>
<i-ho-x-circle
Expand Down
29 changes: 18 additions & 11 deletions src/components/SpaceDelegatesDelegateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
const { notify } = useFlashNotification();
const { t } = useI18n();
const { resolveName } = useResolveName();
const { setDelegate, loadDelegateBalance, isLoadingDelegateBalance } =
const { setDelegates, loadDelegateBalance, isLoadingDelegateBalance } =
useDelegates(props.space);
const { formatCompactNumber } = useIntl();
const { web3Account } = useWeb3();
Expand Down Expand Up @@ -73,7 +73,7 @@ async function handleConfirm() {
const txPendingId = createPendingTransaction();
try {
isAwaitingSignature.value = true;
const tx = await setDelegate(resolvedAddress.value);
const tx = await setDelegates([resolvedAddress.value]);
isAwaitingSignature.value = false;
updatePendingTransaction(txPendingId, { hash: tx.hash });
emit('close');
Expand All @@ -87,6 +87,7 @@ async function handleConfirm() {
} catch (e) {
console.log(e);
isAwaitingSignature.value = false;
notify(['red', 'An error occurred while building the transaction.']);
removePendingTransaction(txPendingId);
}
}
Expand Down Expand Up @@ -137,19 +138,25 @@ watch(
<div class="px-4 pt-1 text-left text-skin-heading">
<h3 class="m-0">{{ $t('delegates.delegateModal.title') }}</h3>
<span>{{ $t('delegates.delegateModal.sub') }}</span>
<LoadingSpinner
v-if="isLoadingDelegateBalance"
class="inline-block pl-2"
small
/>
<span v-else>
{{ formatCompactNumber(Number(accountBalance)) }}
{{ space.symbol }}
</span>
</div>
</template>

<div class="space-y-3 p-4">
<div>
<LabelInput> Voting power </LabelInput>
<div class="mt-1 flex items-center gap-1 text-skin-heading">
<LoadingSpinner
v-if="isLoadingDelegateBalance"
class="inline-block"
small
/>
<span v-else>
{{ formatCompactNumber(Number(accountBalance)) }}
{{ space.symbol }}
</span>
</div>
</div>

<div>
<LabelInput> Delegation scope </LabelInput>
<div class="mt-1 flex items-center gap-1">
Expand Down
Loading

0 comments on commit bddda20

Please sign in to comment.