1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/actions/contract_list_actions.js
2016-02-05 10:38:59 +01:00

55 lines
1.5 KiB
JavaScript

'use strict';
import { alt } from '../alt';
import OwnershipFetcher from '../fetchers/ownership_fetcher';
import Q from 'q';
class ContractListActions {
constructor() {
this.generateActions(
'updateContractList',
'flushContractList'
);
}
fetchContractList(isActive, isPublic, issuer) {
return Q.Promise((resolve, reject) => {
OwnershipFetcher.fetchContractList(isActive, isPublic, issuer)
.then((contracts) => {
this.actions.updateContractList(contracts.results);
resolve(contracts.results);
})
.catch((err) => {
console.logGlobal(err);
this.actions.updateContractList([]);
reject(err);
});
});
}
changeContract(contract) {
return Q.Promise((resolve, reject) => {
OwnershipFetcher.changeContract(contract)
.then(resolve)
.catch((err)=> {
console.logGlobal(err);
reject(err);
});
});
}
removeContract(contractId) {
return Q.Promise((resolve, reject) => {
OwnershipFetcher.deleteContract(contractId)
.then(resolve)
.catch((err) => {
console.logGlobal(err);
reject(err);
});
});
}
}
export default alt.createActions(ContractListActions);