Skip to content

Commit

Permalink
Add popover to add pairs to blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed May 27, 2020
1 parent fa7d4ab commit 5afe652
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/components/ftbot/FTBotAPIPairList.vue
Expand Up @@ -21,7 +21,31 @@
<hr />

<!-- Blacklsit -->
<h3>Blacklist</h3>
<div>
<label class="mr-auto h3">Blacklist</label>
<b-button id="blacklist-add-btn" class="float-right" size="sm">+</b-button>
<b-popover target="blacklist-add-btn" triggers="click" :show.sync="blackListShow">
<form ref="form">
<div>
<b-form-group label-cols="2" label="Pair" label-for="pair-input">
<b-form-input
id="pair-input"
v-model="newblacklistpair"
required
autofocus
></b-form-input>
</b-form-group>
<b-button
class="float-right mb-2"
id="blacklist-submit"
size="sm"
@click="addBlacklistPair"
>Add</b-button
>
</div>
</form>
</b-popover>
</div>
<div v-if="blacklist.length" class="list">
<b-list-group v-for="(pair, key) in blacklist" :key="key">
<b-list-group-item href="#" class="pair black">{{ pair }}</b-list-group-item>
Expand All @@ -39,7 +63,10 @@ import { mapState, mapActions } from 'vuex';
export default {
name: 'FTBotAPIPairList',
data() {
return {};
return {
newblacklistpair: '',
blackListShow: false,
};
},
created() {
this.init();
Expand All @@ -48,7 +75,7 @@ export default {
...mapState('ftbot', ['whitelist', 'blacklist', 'pairlistMethods']),
},
methods: {
...mapActions('ftbot', ['getWhitelist', 'getBlacklist']),
...mapActions('ftbot', ['getWhitelist', 'getBlacklist', 'addBlacklist']),
init() {
if (this.whitelist.length === 0) {
this.getWhitelist();
Expand All @@ -57,6 +84,14 @@ export default {
this.getBlacklist();
}
},
addBlacklistPair() {
if (this.newblacklistpair) {
this.blackListShow = false;
this.addBlacklist({ blacklist: [this.newblacklistpair] });
this.newblacklistpair = '';
}
},
},
};
</script>
Expand Down
32 changes: 32 additions & 0 deletions src/store/modules/ftbot.js
Expand Up @@ -202,5 +202,37 @@ export default {
reject(error);
});
},
addBlacklist({ commit, dispatch }, payload) {
console.log(`Adding ${payload} to blacklist`);
if (payload && payload.blacklist) {
return api
.post('/blacklist', payload)
.then((result) => {
commit('updateBlacklist', result.data);
dispatch(
'alerts/addAlert',
{ message: `Pairs ${payload.blacklist} added` },
{ root: true },
);
})
.catch((error) => {
console.error(error.response);
dispatch(
'alerts/addAlert',
{
message: `Error occured while adding pairs to Blacklist: '${error.response.data.error}'`,
severity: 'danger',
},
{ root: true },
);
});
}
// Error branchs
const error = 'Pair is empty';
console.error(error);
return new Promise((resolve, reject) => {
reject(error);
});
},
},
};

0 comments on commit 5afe652

Please sign in to comment.