1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/actions/contract_actions.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
import alt from '../alt';
import OwnershipFetcher from '../fetchers/ownership_fetcher';
2015-08-28 16:18:10 +02:00
class ContractActions {
constructor() {
this.generateActions(
2015-08-28 16:18:10 +02:00
'updateContract',
'flushContract'
);
}
fetchContract(email) {
if(email.match(/.+\@.+\..+/)) {
2015-08-28 16:18:10 +02:00
OwnershipFetcher.fetchContract(email)
.then((contracts) => {
if (contracts && contracts.length > 0) {
2015-08-28 16:18:10 +02:00
this.actions.updateContract({
contractKey: contracts[0].s3Key,
2015-07-15 14:48:51 +02:00
contractUrl: contracts[0].s3Url,
contractEmail: email
});
}
else {
2015-08-28 16:18:10 +02:00
this.actions.updateContract({
contractKey: null,
2015-07-15 14:48:51 +02:00
contractUrl: null,
contractEmail: null
});
}
})
.catch((err) => {
2015-07-17 15:41:09 +02:00
console.logGlobal(err);
2015-08-28 16:18:10 +02:00
this.actions.updateContract({
contractKey: null,
2015-07-15 14:48:51 +02:00
contractUrl: null,
contractEmail: null
});
});
}
}
2015-09-03 15:53:02 +02:00
}
2015-08-28 16:18:10 +02:00
export default alt.createActions(ContractActions);