Skip to content

Commit

Permalink
Merge pull request #256 from tescher/feature/parcel-and-discord-jumps
Browse files Browse the repository at this point in the history
Feature/parcel and discord jumps
  • Loading branch information
tescher authored Nov 3, 2022
2 parents f148cfd + 545502c commit aecdb0e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {
required,
validNonNegativeDecimal,
} from '@app/utils/formUtils';
import ALLOWED_CURRENCIES from '@app/constants/currency';

const useCurrencies = (): string[] => {
return ['BANK'];
return ALLOWED_CURRENCIES;
};

const PLACEHOLDERS = {
Expand All @@ -33,7 +34,7 @@ export const bountyFormFieldValues = {
title: '',
description: '',
reward: '1000',
currency: 'BANK',
currency: ALLOWED_CURRENCIES[0],
criteria: '',
dueAt: new Date().toISOString(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const NotNeededFields = [
'creatorMessage',
'claimantMessage',
'createdInChannel',
'payeeData',
] as const;

const useCachedForm = () => {
Expand Down
60 changes: 32 additions & 28 deletions packages/react-app/src/components/pages/Bounties/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useUser } from '@app/hooks/useUser';
import { useRoles } from '@app/hooks/useRoles';

import SavedQueriesMenu from './Filters/SavedQueriesMenu';
import { ALLOWED_CURRENCIES_TYPE, ALLOWED_CURRENCY_CONTRACTS } from '@app/constants/currency';
import ServiceUtils from '@app/utils/ServiceUtils';

export const PAGE_SIZE = 10;
Expand Down Expand Up @@ -94,25 +95,13 @@ const SelectExport = ({
setSelectedBounties([]);
};

const handleCSV = (claimedOnly = false, extraMapFunc?: (bounty: Record<string, unknown>) => Record<string, unknown>): void => {
if (bounties && csvLink.current) {
let csvData = [];
if (claimedOnly) {
csvData = bounties
.filter(({ _id }) => selectedBounties.includes(_id))
.filter(bounty => bounty.claimedBy)
.map(miscUtils.csvEncode);
} else {
csvData = bounties
.filter(({ _id }) => selectedBounties.includes(_id))
.map(miscUtils.csvEncode);
}
if (extraMapFunc) {
csvData = csvData.map(bounty => extraMapFunc(bounty));
}
setCsvData(csvData, () => {
const handleCSV = (exportBounties: any[]): void => {
if (exportBounties && csvLink.current) {
setCsvData(exportBounties, () => {
csvLink?.current?.link.click();
});
// TODO - redo all this as part of the Mark as Paid project.

if (user && roles) {
let bountiesToMark: string[] = [];
// If Admin, allow all to be marked, otherwise only own bounties and if correct permissions
Expand Down Expand Up @@ -201,31 +190,46 @@ const SelectExport = ({
<MenuItem
onClick={ () => {
setCsvFormat(BOUNTY_PARCEL_EXPORT_ITEMS);
handleCSV(true, function(bounty: any) {
if (bounty['claimedBy']) {
bounty['compositeName'] = bounty['claimedBy']['discordHandle'];
}
bounty['compositeName'] += ' - ' + bounty['title'];
return bounty;
});
if (bounties) {
const exportBounties = (bounties
.filter(({ _id }) => selectedBounties.includes(_id))
.filter(bounty => bounty.claimedBy && bounty.payeeData.walletAddress && ALLOWED_CURRENCY_CONTRACTS[bounty.reward.currency as ALLOWED_CURRENCIES_TYPE]) as any[])
.map((bounty) => {
if (bounty['claimedBy']) {
bounty['compositeName'] = bounty['claimedBy']['discordHandle'];
}
if (bounty.reward) {
bounty.reward.currency = ALLOWED_CURRENCY_CONTRACTS[bounty.reward.currency as ALLOWED_CURRENCIES_TYPE];
}
bounty['compositeName'] += ' - ' + bounty['title'];
return miscUtils.csvEncode(bounty);
});
handleCSV(exportBounties);
}
} }
>
Parcel.money format (only claimed bounties)
Parcel.money format
</MenuItem>
<MenuItem
onClick={ () => {
setCsvFormat(BOUNTY_LIMITED_EXPORT_ITEMS);
handleCSV();
if (bounties) {
const exportBounties = bounties
.filter(({ _id }) => selectedBounties.includes(_id))
.filter(bounty => bounty.claimedBy)
.map(miscUtils.csvEncode);
handleCSV(exportBounties);
}
} }
>
Limited data (CSV format)
CSV format
</MenuItem>
<MenuItem
onClick={ () => {
handleJSON();
} }
>
All data (JSON format)
JSON format
</MenuItem>
</MenuList>
</Menu>
Expand Down
15 changes: 15 additions & 0 deletions packages/react-app/src/constants/currency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ObjectKeys } from 'react-hook-form/dist/types/path/common';

export const ALLOWED_CURRENCY_CONTRACTS = {
'BANK': '0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198',
'ETH': 'ETH',
'USDC': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'USDT': '0xdAC17F958D2ee523a2206206994597C13D831ec7',
'BTC': '',
};

export const ALLOWED_CURRENCIES = Object.keys(ALLOWED_CURRENCY_CONTRACTS);
export type ALLOWED_CURRENCIES_TYPE = ObjectKeys<typeof ALLOWED_CURRENCY_CONTRACTS>;


export default ALLOWED_CURRENCIES;
5 changes: 5 additions & 0 deletions packages/react-app/src/models/Bounty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export const MessageInfo = object({
messageId: string(),
channelId: string(),
});
export const PayeeData = object({
walletAddress: string(),
userDiscordId: string(),
});

export const BountySchema = object({
_id: string().optional(),
Expand Down Expand Up @@ -171,6 +175,7 @@ export const BountySchema = object({
paidStatus: paidStatus.optional(),
paidAt: string().optional(),
paidBy: DiscordUser.optional(),
payeeData: PayeeData.optional(),

statusHistory: array(StatusHistory).optional(),
activityHistory: array(ActivityHistory).optional(),
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// Extract the string values of an object as a union of typescript string literals
export type ObjectValues<T extends Record<string, string>> = T[keyof T];
export type ObjectKeys<T extends Record<string, string>> = keyof T;

0 comments on commit aecdb0e

Please sign in to comment.