Skip to content

Commit

Permalink
Merge pull request #1286 from aeternity/feature/update-pointers
Browse files Browse the repository at this point in the history
Update state after name pointing
  • Loading branch information
davidyuk authored Nov 20, 2019
2 parents e347ac8 + bd557d7 commit a27b354
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/pages/mobile/NameDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export default {
return owned && owned.names.find(({ name }) => name === this.name);
},
}),
async mounted() {
const id = setInterval(() => this.$store.dispatch('names/fetchOwned'), 3000);
this.$once('hook:destroyed', () => clearInterval(id));
},
};
</script>

Expand Down
7 changes: 3 additions & 4 deletions src/pages/mobile/NameNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ export default {
this.$store.dispatch('names/fetchOwned');
await this.$store.state.sdk.poll(claimTxHash);
if (MAX_AUCTION_NAME_LENGTH < this.name.length) {
await this.$store.state.sdk.aensUpdate(
(await this.$store.state.sdk.api.getNameEntryByName(this.name)).id,
this.$store.getters['accounts/active'].address,
);
await this.$store.dispatch('names/updatePointer', {
name: this.name, address: this.$store.getters['accounts/active'].address,
});
}
this.$store.dispatch('modals/open', {
name: 'notification',
Expand Down
6 changes: 3 additions & 3 deletions src/pages/mobile/NameTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export default {
}
this.busy = true;
try {
await this.$store.state.sdk[`aens${this.pointing ? 'Update' : 'Transfer'}`](
this.nameEntry.nameHash, this.accountTo,
);
await (this.pointing
? this.$store.dispatch('names/updatePointer', { name: this.name, address: this.accountTo })
: this.$store.state.sdk.aensTransfer(this.nameEntry.nameHash, this.accountTo));
this.$store.dispatch('modals/open', {
name: 'notification',
text: this.pointing
Expand Down
19 changes: 15 additions & 4 deletions src/store/plugins/ui/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default (store) => {
},
getters: {
get: ({ names }, getters, { accounts: { list } }, rootGetters) => (id, local = true) => {
store.dispatch('names/fetch', id);
store.dispatch('names/fetch', { id });
if (names[id].name) return names[id].name;
if (local) {
const account = list.find(a => a.address === id);
Expand All @@ -27,7 +27,7 @@ export default (store) => {
},
getAddress: ({ names }) => (id) => {
if (Crypto.isAddressValid(id)) return id;
store.dispatch('names/fetch', id);
store.dispatch('names/fetch', { id });
if (names[id].address) return names[id].address;
return '';
},
Expand Down Expand Up @@ -63,8 +63,8 @@ export default (store) => {
},
async fetch({
rootState, state, commit, dispatch,
}, id) {
if (state.names[id]) return;
}, { id, force }) {
if (!force && state.names[id]) return;
commit('set', { key: id });
const sdk = rootState.sdk.then ? await rootState.sdk : rootState.sdk;
if (id.startsWith('ak_')) {
Expand Down Expand Up @@ -141,6 +141,17 @@ export default (store) => {
})),
};
},
async updatePointer({
rootState: { sdk }, state, commit, dispatch,
}, { name, address }) {
const nameEntry = await sdk.api.getNameEntryByName(name);
await sdk.aensUpdate(nameEntry.id, address);
const prevAddr = getAddressByNameEntry(nameEntry);
if (prevAddr && state.names[prevAddr] && state.names[prevAddr].hash === nameEntry.id) {
commit('set', { address: prevAddr });
}
await dispatch('fetch', { id: name, force: true });
},
},
});

Expand Down

0 comments on commit a27b354

Please sign in to comment.