Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case 'dac':
options.delegateId = entity.delegateId;
options.delegateTypeId = entity.id;
options.status = Donation.WAITING;
break;
case 'campaign':
options.ownerId = entity.projectId;
options.ownerTypeId = entity.id;
options.status = Donation.COMMITTED;
break;
default:
break;
}
const query = paramsForServer({
query: {
amountRemaining: { $ne: 0 },
...options,
$sort: { createdAt: 1 },
'token.symbol': this.state.selectedToken.symbol,
},
schema: 'includeTypeAndGiverDetails',
});
// start watching donations, this will re-run when donations change or are added
this.donationsObserver = feathersClient
.service('donations')
.watch({ listStrategy: 'always' })
.find(query)
.subscribe(
donations => {
loadUserDonations() {
this.donationsObserver = feathersClient
.service('donations')
.watch({ listStrategy: 'always' })
.find(
paramsForServer({
schema: 'includeTypeDetails',
query: {
giverAddress: this.state.userAddress,
homeTxHash: { $exists: true },
// no parentDonations is the 1st of 2 Transfer events emitted when a new donation occurs
// we want to exclude those
parentDonations: { $ne: [] },
canceledPledgeId: null,
$limit: this.state.itemsPerPage,
$skip: this.state.skipDonationsPages * this.state.itemsPerPage,
},
}),
)
.subscribe(
resp => {
this.setState({
id: milestoneId,
fiatAmount: new BigNumber(resp.data[0].fiatAmount || '0').toFixed(2),
totalDonated: convertEthHelper(resp.data[0].totalDonated),
maxAmount: convertEthHelper(resp.data[0].maxAmount),
}),
),
)
.catch(err => {
ErrorPopup('Something went wrong with viewing the milestone. Please try a refresh.', err);
this.setState({ isLoading: false });
});
// lazy load donations
// TODO: fetch "non committed" donations? add "intendedProjectTypeId: milestoneId" to query to get
// all "pending approval" donations for this milestone
const query = paramsForServer({
query: {
ownerTypeId: milestoneId,
amountRemaining: { $ne: 0 },
status: { $ne: Donation.FAILED },
},
schema: 'includeGiverDetails',
$sort: { createdAt: -1 },
});
this.donationsObserver = feathersClient
.service('donations')
.watch({ listStrategy: 'always' })
.find(query)
.subscribe(
resp =>
this.setState({
getAndWatchDonations() {
// here we get all the ids.
// TODO: less overhead here if we move it all to a single service.
// NOTE: This will not rerun, meaning after any dac/campaign/milestone is added
const dacsIds = this.state.dacs
.filter(c => c.ownerAddress === this.props.currentUser.address)
.map(c => c._id);
const campaignIds = this.state.campaigns
.filter(c => c.ownerAddress === this.props.currentUser.address)
.map(c => c._id);
const query = paramsForServer({
query: {
amountRemaining: { $ne: 0 },
$or: [
{ ownerTypeId: { $in: campaignIds }, status: Donation.COMMITTED },
{
delegateTypeId: { $in: dacsIds },
status: { $in: [Donation.WAITING, Donation.TO_APPROVE] },
},
{
ownerTypeId: this.props.currentUser.address,
delegateId: { $exists: false },
status: Donation.WAITING,
},
// {
// ownerTypeId: this.props.currentUser.address,
// delegateTypeId: { $gt: 0 },
static subscribeDonations(id, onSuccess, onError) {
return feathersClient
.service('donations')
.watch({ listStrategy: 'always' })
.find(
paramsForServer({
query: {
status: { $ne: Donation.FAILED },
delegateTypeId: id,
isReturn: false,
intendedProjectId: { $exists: false },
$sort: { createdAt: -1 },
},
schema: 'includeTypeAndGiverDetails',
}),
)
.subscribe(resp => {
onSuccess(resp.data.map(d => new Donation(d)));
}, onError);
}
loadDonations() {
if (this.props.currentUser === undefined) return;
this.donationsObserver = feathersClient
.service('donations')
.watch({ listStrategy: 'always' })
.find(
paramsForServer({
schema: 'includeTypeDetails',
query: {
giverAddress: this.props.currentUser.address,
amountRemaining: { $ne: 0 },
$limit: this.state.itemsPerPage,
$skip: this.state.skipPages * this.state.itemsPerPage,
$sort: { createdAt: -1 },
},
}),
)
.subscribe(
resp => {
this.setState(prevState => ({
donations: resp.data.map(d => new Donation(d)),
skipPages: resp.skip / prevState.itemsPerPage,
totalResults: resp.total,
static getDonations(id, $limit = 100, $skip = 0, onSuccess = () => {}, onError = () => {}) {
return feathersClient
.service('donations')
.find(
paramsForServer({
query: {
status: { $ne: Donation.FAILED },
$or: [{ intendedProjectTypeId: id }, { ownerTypeId: id }],
ownerTypeId: id,
isReturn: false,
$sort: { createdAt: -1 },
$limit,
$skip,
},
schema: 'includeTypeAndGiverDetails',
}),
)
.then(resp => onSuccess(resp.data.map(d => new Donation(d)), resp.total))
.catch(onError);
}
static getDonations(id, $limit = 100, $skip = 0, onSuccess = () => {}, onError = () => {}) {
return feathersClient
.service('donations')
.find(
paramsForServer({
query: {
$or: [
{
amountRemaining: { $ne: 0 },
status: { $ne: Donation.FAILED },
$or: [{ intendedProjectTypeId: id }, { ownerTypeId: id }],
},
{
status: Donation.PAID,
$or: [{ intendedProjectTypeId: id }, { ownerTypeId: id }],
},
],
$sort: { usdValue: -1, createdAt: -1 },
$limit,
$skip,
},