Skip to content

Commit

Permalink
fix: remove unnecessary name preclaim
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Feb 15, 2025
1 parent de30968 commit a5a4e57
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 129 deletions.
21 changes: 2 additions & 19 deletions src/components/mobile/AccountSwitcherModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
<Overlay class="account-switcher-modal" @click="resolve">
<AeCard fill="maximum">
<ListItemAccount
v-for="(account, index) in accountsWithNamePending"
v-for="(account, index) in accounts"
:key="account.address"
v-bind="account"
>
<template slot="right">
<NamePending v-if="account.namePending" />
<AeRadio :checked="index === activeIdx" @change="setActiveIdx(index)" />
</template>
</ListItemAccount>
Expand Down Expand Up @@ -45,7 +44,6 @@ import { pick } from 'lodash-es';
import Overlay from '../Overlay.vue';
import ListItem from '../ListItem.vue';
import ListItemAccount from '../ListItemAccount.vue';
import NamePending from './NamePending.vue';
import ListItemCircle from '../ListItemCircle.vue';
import { Plus } from '../icons';
import AeCard from '../AeCard.vue';
Expand All @@ -58,7 +56,6 @@ export default {
Overlay,
ListItem,
ListItemAccount,
NamePending,
ListItemCircle,
Plus,
AeCard,
Expand All @@ -69,17 +66,7 @@ export default {
props: {
resolve: { type: Function, required: true },
},
computed: {
...mapState('accounts', ['activeIdx']),
...mapState('names', {
accountsWithNamePending(state, { get, isPending }) {
return this.accounts.map((account) => ({
...account,
namePending: isPending(get(account.address)),
}));
},
}),
},
computed: mapState('accounts', ['activeIdx']),
subscriptions() {
return pick(this.$store.state.observables, ['accounts', 'totalBalance']);
},
Expand Down Expand Up @@ -131,10 +118,6 @@ export default {
align-self: center;
}
.name-pending {
margin-right: functions.rem(8px);
}
.list-item.vault-new .list-item-circle {
background-color: variables.$color-alternative;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/mobile/ConfirmTransactionSignModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<script>
import { mapState } from 'vuex';
import { Tag } from '@aeternity/aepp-sdk-next';
import { Tag, isAuctionName } from '@aeternity/aepp-sdk-next';
import Page from '../Page.vue';
import Guide from '../Guide.vue';
import AeFraction from '../AeFraction.vue';
Expand Down Expand Up @@ -100,7 +100,7 @@ export default {
guideTemplate() {
const { tag } = this.transaction;
if (tag === Tag.SpendTx) return this.$t('modal.confirm-transaction-sign.guide-spend');
if (tag === Tag.NameClaimTx && !+this.transaction.nameSalt) {
if (tag === Tag.NameClaimTx && isAuctionName(this.transaction.name)) {
return this.$t('modal.confirm-transaction-sign.guide-name-bid');
}
return this.$t('modal.confirm-transaction-sign.guide', {
Expand Down
29 changes: 0 additions & 29 deletions src/components/mobile/NamePending.vue

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const MAGNITUDE_MICRO = -6;
export const MAGNITUDE_PICO = -12;

export const AENS_DOMAIN = '.chain';
export const MAX_AUCTION_NAME_LENGTH = 12 + AENS_DOMAIN.length;

export const NAME_LIST_ROUTE_NAMES = ['name-list', 'auction-list', 'auction-list-character-length'];

Expand Down
1 change: 0 additions & 1 deletion src/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@
"confirm-bidding": "An auction for the name {name} has already started. Would you like to make a bid?",

"notification": {
"claim-sent": "为{name} 的名称已成功发送",
"registered": "{name} 已成功注册",
"bid": "You bid on {name} successfully",
"unknown-error": "因为未知原因,{name} 未注册"
Expand Down
1 change: 0 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@
"confirm-bidding": "An auction for the name {name} has already started. Would you like to make a bid?",

"notification": {
"claim-sent": "Claim for {name} name was successfully sent",
"registered": "{name} was successfully registered",
"bid": "You bid on {name} successfully",
"unknown-error": "{name} was not registered for unknown reason"
Expand Down
1 change: 0 additions & 1 deletion src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@
"confirm-bidding": "An auction for the name {name} has already started. Would you like to make a bid?",

"notification": {
"claim-sent": "La solicitud de {name} nombre se envió correctamente",
"registered": "{name} se registró correctamente",
"bid": "You bid on {name} successfully",
"unknown-error": "{name} no se registró por un motivo desconocido"
Expand Down
1 change: 0 additions & 1 deletion src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@
"confirm-bidding": "Аукцион на имя {name} уже начался. Хотите сделать ставку?",

"notification": {
"claim-sent": "Запрос на имя {name} был успешно отправлен​​",
"registered": "{name} было успешно зарегистрировано",
"bid": "Вы успешно поставили на {name}",
"unknown-error": "{name} не было зарегистрировано по неизвестной причине"
Expand Down
2 changes: 2 additions & 0 deletions src/pages/aens/AuctionDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export default {
async updateBids() {
const { data } = await this.$store.getters.middleware
// TODO: show more than 100 bids
// TODO: use /v3/names/auction.chain/claims instead
// TODO: remove previous bids after solving https://github.com/aeternity/ae_mdw/issues/2097
.getAccountActivities(produceNameId(this.name), { limit: 100 });
this.bids = data
.filter(({ type }) => type === 'NameClaimEvent')
Expand Down
6 changes: 1 addition & 5 deletions src/pages/aens/NameList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
:name="entry.name"
:to="{ name: 'name-details', params: { name: entry.name } }"
subtitle="address"
>
<NamePending v-if="entry.status === 'pending'" slot="right" />
</ListItemAccount>
/>
</AeCard>
</template>

Expand Down Expand Up @@ -48,7 +46,6 @@ import Page from '../../components/Page.vue';
import NameListHeader from '../../components/mobile/NameListHeader.vue';
import AeCard from '../../components/AeCard.vue';
import ListItemAccount from '../../components/ListItemAccount.vue';
import NamePending from '../../components/mobile/NamePending.vue';
import ButtonAddFixed from '../../components/ButtonAddFixed.vue';
import { MAGNITUDE } from '../../lib/constants';
Expand All @@ -58,7 +55,6 @@ export default {
NameListHeader,
AeCard,
ListItemAccount,
NamePending,
ButtonAddFixed,
},
data: () => ({ auctions: [] }),
Expand Down
29 changes: 6 additions & 23 deletions src/pages/aens/NameNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@

<script>
import { mapGetters } from 'vuex';
import { Name } from '@aeternity/aepp-sdk-next';
import { MAX_AUCTION_NAME_LENGTH } from '../../lib/constants';
import { Name, isAuctionName } from '@aeternity/aepp-sdk-next';
import { handleUnknownError, isNotFoundError } from '../../lib/utils';
import { i18n } from '../../store/plugins/ui/languages';
import Page from '../../components/Page.vue';
Expand Down Expand Up @@ -83,27 +82,9 @@ export default {
}
const name = new Name(this.name, this.$store.getters.sdk.getContext());
let claimTxHash;
try {
await name.preclaim();
claimTxHash = (await name.claim({ waitMined: false })).hash;
this.$store.dispatch('modals/open', {
name: 'notification',
text: this.$t('name.new.notification.claim-sent', { name: this.name }),
});
this.$router.push({ name: 'name-list' });
} catch (e) {
if (e.message === 'Rejected by user') return;
this.error = true;
handleUnknownError(e);
} finally {
this.busy = false;
}
try {
this.$store.dispatch('names/fetchOwned');
await this.$store.getters.sdk.poll(claimTxHash);
const isAuction = MAX_AUCTION_NAME_LENGTH >= this.name.length;
await name.claim();
const isAuction = isAuctionName(this.name);
if (!isAuction) {
await this.$store.dispatch('names/updatePointer', {
name: this.name,
Expand All @@ -116,15 +97,17 @@ export default {
? i18n.t('name.new.notification.bid', { name: this.name })
: i18n.t('name.new.notification.registered', { name: this.name }),
});
this.$router.push({ name: 'name-list' });
} catch (e) {
if (e.message === 'Rejected by user') return;
this.error = true;
this.$store.dispatch('modals/open', {
name: 'notification',
text: i18n.t('name.new.notification.unknown-error', { name: this.name }),
});
handleUnknownError(e);
} finally {
this.$store.dispatch('names/fetchOwned');
this.busy = false;
}
},
},
Expand Down
37 changes: 5 additions & 32 deletions src/store/plugins/ui/names.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import BigNumber from 'bignumber.js';
import Vue from 'vue';
import { isAddressValid, Name, produceNameId } from '@aeternity/aepp-sdk-next';
import { MAGNITUDE } from '../../../lib/constants';
import {
handleUnknownError, isAccountNotFoundError, getAddressByNameEntry, isAensName,
} from '../../../lib/utils';
import { getAddressByNameEntry, isAensName } from '../../../lib/utils';

export default (store) => {
store.registerModule('names', {
Expand Down Expand Up @@ -42,9 +38,6 @@ export default (store) => {
getDefault: ({ defaults }, _getters, { sdkSync: { networkId } }) => (address) => (
defaults[`${address}-${networkId}`]
),
isPending: ({ owned }) => (name) => (
!!((owned.find((t) => t.name === name)) || {}).status === 'pending'
),
},
mutations: {
set({ names }, {
Expand Down Expand Up @@ -109,37 +102,18 @@ export default (store) => {
throw new Error(`Unknown id: ${id}`);
},
async fetchOwned({ rootState, rootGetters: { node, middleware }, commit }) {
const getPendingNameClaimTransactions = (address) => node
.getPendingAccountTransactionsByPubkey(address)
.then(
({ transactions }) => transactions
.filter(({ tx: { type } }) => type === 'NameClaimTx')
.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} activeFrom - block height
* @property {number | undefined} expireHeight - block height
* @property {'auction' | 'name' | 'pending'} status
* @property {'auction' | 'name'} status
* @property {BigNumber | undefined} nameFee
*/
const names = (await Promise.all(
rootState.accounts.list.map(({ address }) => Promise.all([
getPendingNameClaimTransactions(address),
rootState.accounts.list.map(({ address }) =>
middleware.getNames({ ownedBy: address, limit: 100, state: 'active' })
.then(({ data }) => data.map(({ name, pointers, activeFrom, expireHeight }) => ({
name,
Expand All @@ -148,9 +122,8 @@ export default (store) => {
activeFrom,
expireHeight,
status: 'name',
}))),
])),
)).flat(2);
})))),
)).flat(1);

commit('setOwned', names);
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
10 changes: 0 additions & 10 deletions tests/e2e/specs/names/auctions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ describe('Auctions', () => {
cy.get('input').type(`${name}{moveToStart}${'{rightArrow}'.repeat(4)}-`);
cy.get('.ae-button').click();

cy.get('.turtle-rabbit').should('be.visible');
cy.contains('Preclaim');
cy.get('.ae-button-group .secondary').click();

cy.get('.turtle-rabbit').should('be.visible');
cy.matchImage();
cy.get('.ae-button-group .secondary').click();

cy.get('.notification')
.contains('You bid on')
.contains('successfully')
.should('be.visible')
.invoke('remove');

cy.get('.notification')
.contains('Claim for')
.contains('name was successfully sent')
.should('be.visible');
});

Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/specs/names/long-names.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ describe('Long names', () => {
cy.get('input').type(`${name}{moveToStart}${'{rightArrow}'.repeat(4)}-`);
cy.get('.ae-button').click();

cy.get('.turtle-rabbit').should('be.visible');
cy.matchImage({ screenshotConfig: { blackout: ['.details-raw-data code'] } });
cy.get('.ae-button-group .secondary').click();

cy.get('.turtle-rabbit').should('be.visible');
cy.matchImage();
cy.get('.ae-button-group .secondary').click();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5a4e57

Please sign in to comment.