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 NameDetails #1526

Merged
merged 3 commits into from
Jan 11, 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
1 change: 1 addition & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export class DOMRect {
get bottom() { return this.top + this.height; }
}

// name entry returned by node, not middleware
export const getAddressByNameEntry = (nameEntry) => ((nameEntry.pointers
&& nameEntry.pointers.find(({ key }) => key === 'account_pubkey')) || {}).id;
3 changes: 1 addition & 2 deletions src/pages/aens/AuctionBid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ export default {
const sdk = await Promise.resolve(this.$store.state.sdk);
const res = await sdk.middleware.api.getNameById(name);
if (res.status !== 'auction') throw new Error(`Unexpected name status: ${res.status}`);
// TODO: remove after resolving https://github.com/aeternity/ae_mdw/issues/509
const { auctionEnd, lastBid } = res.auction ?? res.info;
const { auctionEnd, lastBid } = res.info;
this.auctionEnd = auctionEnd;
this.lastBid = new BigNumber(lastBid.tx.nameFee).shiftedBy(-MAGNITUDE);
})();
Expand Down
4 changes: 1 addition & 3 deletions src/pages/aens/AuctionDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ export default {
methods: {
async updateAuctionEntry() {
const sdk = await Promise.resolve(this.$store.state.sdk);
const res = await sdk.middleware.api.getNameById(this.name);
// TODO: remove after resolving https://github.com/aeternity/ae_mdw/issues/509
const { auctionEnd, bids } = res.auction ?? res.info;
const { info: { auctionEnd, bids } } = await sdk.middleware.api.getNameById(this.name);
this.auctionEnd = auctionEnd;
this.bids = await Promise.all(bids.map(async (txId) => {
const { tx } = await sdk.middleware.api.getTxByIndex(txId);
Expand Down
31 changes: 14 additions & 17 deletions src/pages/aens/NameDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:left-button-to="{ name: 'name-list' }"
>
<DetailsList
:object="details"
:object="{ ...details, nameHash }"
:field-renderers="fieldRenderers"
/>

Expand All @@ -17,10 +17,7 @@
{{ $t('name.details.set-default') }}
</AeButton>

<AeButton
:disabled="!address"
@click="extendName"
>
<AeButton @click="extendName">
{{ $t('name.details.to-extend') }}
</AeButton>

Expand All @@ -40,6 +37,7 @@

<script>
import { mapState, mapGetters } from 'vuex';
import { TxBuilderHelper } from '@aeternity/aepp-sdk';
import prefixedAmount from '../../filters/prefixedAmount';
import Page from '../../components/Page.vue';
import DetailsList from '../../components/mobile/DetailsList.vue';
Expand All @@ -65,7 +63,7 @@ export default {
name: Name,
nameHash: NameId,
owner: OwnerId,
createdAtHeight: CreatedAtHeight,
createdAt: CreatedAtHeight,
expiresAt: ExpiresAtHeight,
pointers: DetailsNamePointers,
},
Expand All @@ -77,16 +75,15 @@ export default {
...mapGetters(['currentNetwork']),
...mapState('names', {
details({ owned }) {
const entry = owned && owned.names.find(({ name }) => name === this.name);
return {
...entry,
owner: entry.accountId ?? entry.info.ownership.current,
};
return owned?.names.find(({ name }) => name === this.name);
},
isDefaultName(state, { getDefault }) {
return this.address && this.name === getDefault(this.address);
},
}),
nameHash() {
return TxBuilderHelper.produceNameId(this.name);
},
},
async mounted() {
const id = setInterval(() => this.$store.dispatch('names/fetchOwned'), 3000);
Expand All @@ -101,19 +98,19 @@ export default {
},
async extendName() {
const initialAccountIdx = this.$store.state.accounts.activeIdx;
const requredAccountIdx = this.$store.state.accounts.list
.findIndex(({ address }) => address === this.details.info.ownership.current);
if (initialAccountIdx !== requredAccountIdx) {
this.$store.commit('accounts/setActiveIdx', requredAccountIdx);
const requiredAccountIdx = this.$store.state.accounts.list
.findIndex(({ address }) => address === this.details.owner);
if (initialAccountIdx !== requiredAccountIdx) {
this.$store.commit('accounts/setActiveIdx', requiredAccountIdx);
}
await this.$store.dispatch('names/updatePointer', { name: this.name, address: this.address });
if (initialAccountIdx !== requredAccountIdx) {
if (initialAccountIdx !== requiredAccountIdx) {
this.$store.commit('accounts/setActiveIdx', initialAccountIdx);
}
},
async goToTransactionDetails() {
const { hash } = await this.$store.state.sdk.middleware.api
.getTxByIndex(this.details.info.claims[0]);
.getTxByIndex(this.details.createdAtTxIdx);
await this.$router.push(ENV_MOBILE_DEVICE
? { name: 'transaction-details', params: { hash } }
: `${this.currentNetwork.explorerUrl}/transactions/${hash}`);
Expand Down
7 changes: 3 additions & 4 deletions src/pages/aens/NameList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<ListItemAccount
v-for="entry in owned.names"
:key="entry.name"
:address="entry.accountId || entry.info.ownership.current"
:address="entry.owner"
:name="entry.name"
:to="{ name: 'name-details', params: { name: entry.name } }"
subtitle="address"
>
<NamePending
v-if="entry.pending"
v-if="entry.status === 'pending'"
slot="right"
/>
</ListItemAccount>
Expand All @@ -27,13 +27,12 @@
<template v-if="owned && owned.bids.length">
<h2>{{ $t('name.list.active-bids') }}</h2>
<AeCard fill="maximum">
<!-- TODO: remove `auction || info` after resolving https://github.com/aeternity/ae_mdw/issues/509 -->
<ListItemAccount
v-for="bid in owned.bids"
:key="bid.name"
:name="bid.name"
:balance="bid.nameFee"
:address="(bid.auction || bid.info).lastBid.tx.accountId"
:address="bid.owner"
:to="{ name: 'auction-details', params: { name: bid.name } }"
/>
</AeCard>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/aens/NameTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default {
mounted() {
const initialAccountIdx = this.$store.state.accounts.activeIdx;
const requredAccountIdx = this.$store.state.accounts.list
.findIndex(({ address }) => address === this.nameEntry.info.ownership.current);
.findIndex(({ address }) => address === this.nameEntry.owner);
if (initialAccountIdx !== requredAccountIdx) {
this.$store.commit('accounts/setActiveIdx', requredAccountIdx);
this.$once('hook:destroyed', () => this.$store
Expand Down
64 changes: 49 additions & 15 deletions src/store/plugins/ui/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default (store) => {
sdk.then ? undefined : defaults[`${address}-${sdk.getNetworkId()}`]
),
isPending: ({ owned }) => (name) => (
!!((owned && owned.names.find((t) => t.name === name)) || {}).pending
!!((owned && owned.names.find((t) => t.name === name)) || {}).status === 'pending'
),
},
mutations: {
Expand Down Expand Up @@ -119,34 +119,64 @@ export default (store) => {
.then(
({ transactions }) => transactions
.filter(({ tx: { type } }) => type === 'NameClaimTx')
.map(({ tx, ...otherTx }) => ({
...otherTx,
...tx,
pending: true,
.map(({ tx }) => ({
name: tx.name,
owner: address,
pointers: [],
status: 'pending',
nameFee: new BigNumber(tx.nameFee).shiftedBy(-MAGNITUDE),
})),
(error) => {
if (!isAccountNotFoundError(error)) handleUnknownError(error);
return [];
},
);

/**
* Name object structure
* @property {string} name - name ending with .chain
* @property {string} owner - address
* @property {array} pointers - array of objects with key and value
* @property {number | undefined} createdAt - block height
* @property {number | undefined} createdAtTxIdx - transaction index
* @property {number | undefined} expiresAt - block height
* @property {'auction' | 'name' | 'pending'} status
* @property {BigNumber | undefined} nameFee
*/
const names = (await Promise.all(
rootState.accounts.list.map(({ address }) => Promise.all([
getPendingNameClaimTransactions(address),
sdk.middleware.api.getNamesOwnedBy(address)
.then(({ active, topBid }) => [active, topBid]),
.then(({ active, topBid }) => [
...active.map(({ name, info }) => ({
name,
owner: address,
pointers: Object.entries(info.pointers).map(([key, id]) => ({
// TODO: find a better wrapper for mdw api
key: key === 'accountPubkey' ? 'account_pubkey' : key,
id,
})),
createdAt: info.activeFrom,
createdAtTxIdx: info.claims[0],
expiresAt: info.expireHeight,
status: 'name',
})),
...topBid.map(({ name, info }) => ({
name,
owner: address,
pointers: [],
createdAt: info.lastBid.blockHeight,
createdAtTxIdx: info.lastBid.txIndex,
status: 'auction',
nameFee: new BigNumber(info.lastBid.tx.nameFee).shiftedBy(-MAGNITUDE),
})),
]),
])),
)).flat(Infinity);
)).flat(2);

commit('setOwned', {
names: names.filter(({ status }) => status !== 'auction'),
bids: names.filter(({ status }) => status === 'auction')
.map((bid) => ({
...bid,
// TODO: remove after resolving https://github.com/aeternity/ae_mdw/issues/509
nameFee: new BigNumber((bid.auction ?? bid.info).lastBid.tx.nameFee)
.shiftedBy(-MAGNITUDE),
})),
bids: names.filter(({ status }) => status === 'auction'),
});
},
setDefault({ rootState: { sdk }, commit }, { name, address }) {
Expand All @@ -156,7 +186,11 @@ export default (store) => {
rootState: { sdk }, state, commit, dispatch,
}, { name, address }) {
const nameEntry = await sdk.api.getNameEntryByName(name);
await sdk.aensUpdate(name, [address]);
await sdk.aensUpdate(
name,
address ? { account_pubkey: address } : {},
{ extendPointers: true },
);
const prevAddr = getAddressByNameEntry(nameEntry);
if (prevAddr && state.names[prevAddr] && state.names[prevAddr].hash === nameEntry.id) {
commit('set', { address: prevAddr });
Expand Down
Loading