mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
import alt from '../alt';
|
|
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
|
|
|
|
|
class ContractActions {
|
|
constructor() {
|
|
this.generateActions(
|
|
'updateContract',
|
|
'flushContract'
|
|
);
|
|
}
|
|
|
|
fetchContract(email) {
|
|
if(email.match(/.+\@.+\..+/)) {
|
|
OwnershipFetcher.fetchContract(email)
|
|
.then((contracts) => {
|
|
if (contracts && contracts.length > 0) {
|
|
this.actions.updateContract({
|
|
contractKey: contracts[0].s3Key,
|
|
contractUrl: contracts[0].s3Url,
|
|
contractEmail: email
|
|
});
|
|
}
|
|
else {
|
|
this.actions.updateContract({
|
|
contractKey: null,
|
|
contractUrl: null,
|
|
contractEmail: null
|
|
});
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.logGlobal(err);
|
|
this.actions.updateContract({
|
|
contractKey: null,
|
|
contractUrl: null,
|
|
contractEmail: null
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
export default alt.createActions(ContractActions);
|