Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Add test activity
Browse files Browse the repository at this point in the history
  • Loading branch information
kikakkz committed Dec 6, 2023
1 parent 79b53d9 commit 46b2698
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
13 changes: 13 additions & 0 deletions TestData.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ https://ipfs.moralis.io:2053/ipfs/QmcyuFVLbfBmSeQ9ynu4dk67r97nB1abEekotuVuRGWedm




Map.prototype.forEach() - JavaScript - MDN Web Docs - Mozilla

Return value None (undefined). Description The forEach method executes the provided callback once for each key of the map which actually exist. It is not invoked for keys which have been deleted. However, it is executed for values which are present but have the value undefined. callback is invoked with three arguments: the entry's value the entry's key the Map object being traversed If a thisArg parameter is provided to forEach, it will be passed to callback when invoked, for use as its this value. Otherwise, the value undefined will be passed for use as its this value. The this value ultimately observable by callback is determined according to the usual rules for determining the this seen by a function. Each value is visited once, except in the case when it was deleted and re-added before forEach has finished. callback is not invoked for values deleted before being visited. New values added before forEach has finished will be visited.



Iterating over Typescript Map

Per the TypeScript 2.3 release notes on "New --downlevelIteration": for..of statements, Array Destructuring, and Spread elements in Array, Call, and New expressions support Symbol.iterator in ES5/E3 if available when using --downlevelIteration This is not enabled by default! Add "downlevelIteration": true to your tsconfig.json, or pass --downlevelIteration flag to tsc, to get full iterator support. With this in place, you can write for (let keyval of myMap) {...} and keyval's type will be automatically inferred. Why is this turned off by default? According to TypeScript contributor @aluanhaddad, It is optional because it has a very significant impact on the size of generated code, and potentially on performance, for all uses of iterables (including arrays). If you can target ES2015 ("target": "es2015" in tsconfig.json or tsc --target ES2015) or later, enabling downlevelIteration is a no-brainer, but if you're targeting ES5/ES3, you might benchmark to ensure iterator support doesn't impact performance (if it does, you might be better off with Array.from conversion or forEach or some other workaround).



12 changes: 10 additions & 2 deletions activity/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Activity {
let activity = self.activity(activity_id).await?;
match activity.voters.get(&object_id) {
Some(voters) => match voters.get(&owner) {
Some(_) => Ok(false),
Some(_) => Ok(true),
None => Ok(false),
},
None => Ok(false),
Expand Down Expand Up @@ -209,8 +209,16 @@ impl Activity {
None => HashMap::default(),
};
voters.insert(owner, true);
activity.voters.insert(object_id, voters);
activity.voters.insert(object_id.clone(), voters.clone());
self.activities.insert(&activity_id, activity)?;
log::info!(
"{} vote to {} power {} voters {:?} activity {:?}",
owner,
object_id,
vote_power,
voters,
self.activities.get(&activity_id).await?
);
Ok(())
}
_ => return Err(ActivityError::ActivityObjectNotFound),
Expand Down
35 changes: 31 additions & 4 deletions webui/src/components/CreateActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ watch(_activity, () => {
})
const params = ref({
title: 'The Best Novel of the Month',
slogan: 'Find the best author of the world, and support them!',
banner: 'https://ipfs.moralis.io:2053/ipfs/QmcyuFVLbfBmSeQ9ynu4dk67r97nB1abEekotuVuRGWedm',
hostResume: 'https://www.baidu.com',
posters: [
'https://ipfs.moralis.io:2053/ipfs/QmbzbxQcdcUcdzqrtU1S7cFd7swmcBnytWv5rf1yw94g9s',
'https://ipfs.moralis.io:2053/ipfs/Qmdco6YbN7qK81tNbQw3RmnowSUXiEuaKjG6tt8FsChDuA',
'https://ipfs.moralis.io:2053/ipfs/QmTSfgqeKUNvNUqRfQSFTbPkjjFDtGZFxWQkhyqWwMHhAJ'
],
introduction: 'Within the vote period, user can vote for their favorite novel listed in the candidates. The only criteria is how much you like the novel. The author of the winner novel will get 90% of the reward amount. Remainant part of the reward will be distributed to voter according to their vote power when they vote.',
votable: true,
activityType: ActivityType.Campaign,
voteType: VoteType.Power,
Expand All @@ -227,11 +237,28 @@ const params = ref({
voterRewardPercent: 12,
budgetAmount: '10000000',
registerStartAt: date.formatDate(new Date().toString(), 'YYYY/MM/DD'),
registerEndAt: date.formatDate(new Date().toString(), 'YYYY/MM/DD'),
registerEndAt: date.formatDate(new Date(Date.now() + 3600000000).toString(), 'YYYY/MM/DD'),
voteStartAt: date.formatDate(new Date().toString(), 'YYYY/MM/DD'),
voteEndAt: date.formatDate(new Date().toString(), 'YYYY/MM/DD'),
posters: [] as Array<string>,
prizeConfigs: [] as Array<PrizeConfig>
voteEndAt: date.formatDate(new Date(Date.now() + 3600000000).toString(), 'YYYY/MM/DD'),
prizeConfigs: [
{
place: 1,
medal: 'https://ipfs.moralis.io:2053/ipfs/QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9',
title: 'Best Month Novel',
rewardAmount: '12500.'
}, {
place: 2,
medal: 'https://ipfs.moralis.io:2053/ipfs/QmbvZ2hbF3nEq5r3ijMEiSGssAmJvtyFwiejTAGHv74LR5',
title: 'Better Month Novel',
rewardAmount: '7500.'
}, {
place: 3,
medal: 'https://ipfs.moralis.io:2053/ipfs/QmVpwaCqLut3wqwB5KSQr2fGnbLuJt5e3LhNvzvcisewZB',
title: 'Good Month Novel',
rewardAmount: '2500.'
}
],
location: 'https://ipfs.moralis.io:2053/ipfs/QmcyuFVLbfBmSeQ9ynu4dk67r97nB1abEekotuVuRGWedm'
} as CreateParams)
const newPoster = ref('')
Expand Down
4 changes: 2 additions & 2 deletions webui/src/stores/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useContentStore = defineStore('content', {
let ok = !el.commentToCid
if (author) ok &&= el.author === author
return ok
}).sort((a: Content, b: Content) => a.createdAt - b.createdAt)
}).sort((a: Content, b: Content) => b.createdAt - a.createdAt)
}
},
_recommends (): (cid: string) => Array<Content> {
Expand All @@ -48,7 +48,7 @@ export const useContentStore = defineStore('content', {
return Array.from(this.contents.values()).filter((el) => {
const index = this.comments.get(cid)?.findIndex((el1) => el1 === el.cid)
return index !== undefined && index >= 0
})?.sort((a: Content, b: Content) => a.createdAt < b.createdAt ? 1 : -1) || []
})?.sort((a: Content, b: Content) => b.createdAt - a.createdAt) || []
}
}
},
Expand Down

0 comments on commit 46b2698

Please sign in to comment.