Skip to content

Commit

Permalink
Merge pull request stakwork#589 from stakwork/feat/add_auto_bounty_pe…
Browse files Browse the repository at this point in the history
…nding

PR: Auto bounty pending, and pending alerts
  • Loading branch information
elraphty authored Oct 23, 2024
2 parents 8e923de + 5915667 commit a27e43d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/config/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const palette = {
background100: '#f0f1f3',
statusAssigned: '#49C998',
statusCompleted: '#9B870C',
statusPending: '#ADD8E6',
statusFailed: '#FF0000',
statusPaid: '#8256D0',
button_primary: {
main: '#49C998',
Expand Down
82 changes: 51 additions & 31 deletions src/people/widgetViews/summaries/wantedSummaries/CodingBounty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ function MobileView(props: CodingBountiesProps) {
const [pendingPaymentLoading, setPendingPaymentloading] = useState(false);
const [paidStatus, setPaidStatus] = useState(paid);
const [paymentLoading, setPaymentLoading] = useState(false);
const [localPending, setLocalPending] = useState(false);

const pendingIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);

const userPubkey = ui.meInfo?.owner_pubkey;

let bountyPaid = paid || invoiceStatus || keysendStatus;
const bountyPending = localPending || payment_pending;
const userAssigned = assignee && assignee.owner_pubkey !== '';
let bountyCompleted = completed;

Expand All @@ -145,6 +147,7 @@ function MobileView(props: CodingBountiesProps) {

const addToast = useCallback((type: string) => {
const toastId = Math.random();

switch (type) {
case SOCKET_MSG.invoice_success: {
return setToasts([
Expand All @@ -165,22 +168,24 @@ function MobileView(props: CodingBountiesProps) {
}
]);
}
case SOCKET_MSG.keysend_pending: {
case SOCKET_MSG.keysend_success: {
return setToasts([
{
id: `${toastId}`,
title: 'Payment is pending',
toastLifeTimeMs: 10000,
color: 'warning'
title: 'Paid successfully',
color: 'success'
}
]);
}
case SOCKET_MSG.keysend_success: {
case SOCKET_MSG.keysend_pending: {
setLocalPending(true);

return setToasts([
{
id: `${toastId}`,
title: 'Paid successfully',
color: 'success'
title: 'Payment is pending',
toastLifeTimeMs: 10000,
color: 'warning'
}
]);
}
Expand Down Expand Up @@ -335,7 +340,7 @@ function MobileView(props: CodingBountiesProps) {
}, [main, startPolling]);

useEffect(() => {
if (completed && !paid && assignee && !payment_falied && payment_pending) {
if (completed && !paid && assignee && !payment_falied && bountyPending) {
setPendingPaymentloading(true);
pollPendingPayment(id ?? 0);
}
Expand All @@ -353,7 +358,7 @@ function MobileView(props: CodingBountiesProps) {
payment_falied,
pollPendingPayment,
pendingIntervalRef,
payment_pending
bountyPending
]);

const makePayment = async () => {
Expand All @@ -379,6 +384,7 @@ function MobileView(props: CodingBountiesProps) {
};

await main.makeBountyPayment(body);

setPaymentLoading(false);
recallBounties();
}
Expand Down Expand Up @@ -468,6 +474,8 @@ function MobileView(props: CodingBountiesProps) {
setLocalPaid('UNKNOWN');
setKeysendStatus(true);
addToast(SOCKET_MSG.keysend_success);
} else if (res.msg === SOCKET_MSG.keysend_pending) {
addToast(SOCKET_MSG.keysend_pending);
} else if (res.msg === SOCKET_MSG.keysend_error) {
addToast(SOCKET_MSG.keysend_error);
}
Expand Down Expand Up @@ -551,7 +559,7 @@ function MobileView(props: CodingBountiesProps) {
background: paidStatus ? color.green1 : color.pureWhite,
color: paidStatus ? color.white100 : color.borderGreen1
}}
disabled={payment_pending}
disabled={bountyPending}
data-testid="paid_btn"
text={paidStatus ? unpaidString : paidString}
loading={saving === 'paid' || updatingPayment}
Expand All @@ -575,7 +583,7 @@ function MobileView(props: CodingBountiesProps) {
width={'100%'}
height={48}
disabled={
paymentLoading || payBountyDisable || pendingPaymentLoading || payment_pending
paymentLoading || payBountyDisable || pendingPaymentLoading || bountyPending
}
style={{
bottom: '10px'
Expand All @@ -599,6 +607,29 @@ function MobileView(props: CodingBountiesProps) {
);
}

let pillColor = color.statusAssigned;
if (payment_falied) {
pillColor = color.statusFailed;
} else if (bountyPending) {
pillColor = color.statusPending;
} else if (bountyCompleted && !bountyPaid) {
pillColor = color.statusCompleted;
} else if (bountyPaid) {
pillColor = color.statusPaid;
}

let pillText = 'assigned';

if (payment_falied) {
pillText = 'failed';
} else if (bountyPending) {
pillText = 'pending';
} else if (bountyCompleted) {
pillText = 'completed';
} else if (bountyPaid) {
pillText = 'paid';
}

return (
<div>
{hasAccess ? (
Expand Down Expand Up @@ -702,7 +733,7 @@ function MobileView(props: CodingBountiesProps) {
buttonTextStyle={{
paddingRight: '50px'
}}
disabled={isEditButtonDisable || payment_pending}
disabled={isEditButtonDisable || bountyPending}
/>
<ImageButton
data-testid="delete-btn"
Expand All @@ -715,7 +746,7 @@ function MobileView(props: CodingBountiesProps) {
leadingImageContainerStyle={{
left: 450
}}
disabled={enableDelete || payment_pending}
disabled={enableDelete || bountyPending}
buttonAction={props?.deleteAction}
buttonTextStyle={{
paddingRight: '45px'
Expand Down Expand Up @@ -772,23 +803,12 @@ function MobileView(props: CodingBountiesProps) {
<div className="BountyProfileOuterContainerCreatorView">
<BountyProfileView
assignee={!assignedPerson ? assignee : assignedPerson}
status={
bountyCompleted && !bountyPaid
? 'completed'
: bountyPaid
? 'paid'
: 'assigned'
}
status={pillText}
canViewProfile={false}
statusStyle={{
width: '66px',
height: '16px',
background:
bountyCompleted && !bountyPaid
? color.statusCompleted
: bountyPaid
? color.statusPaid
: color.statusAssigned
background: pillColor
}}
UserProfileContainerStyle={{
height: 48,
Expand All @@ -814,7 +834,7 @@ function MobileView(props: CodingBountiesProps) {
marginLeft: '12px'
}}
/>
{!bountyPaid && !payment_pending && (
{!bountyPaid && !bountyPending && (
<div
data-testid="edit-btn"
className="AssigneeCloseButtonContainer"
Expand Down Expand Up @@ -910,7 +930,7 @@ function MobileView(props: CodingBountiesProps) {
paymentLoading ||
payBountyDisable ||
pendingPaymentLoading ||
payment_pending
bountyPending
}
iconSize={14}
width={220}
Expand Down Expand Up @@ -959,7 +979,7 @@ function MobileView(props: CodingBountiesProps) {
background: color.pureWhite,
color: color.borderGreen1
}}
disabled={payment_pending}
disabled={bountyPending}
text={paidStatus ? unpaidString : paidString}
loading={saving === 'paid' || updatingPayment}
endingImg={'/static/mark_unpaid.svg'}
Expand Down Expand Up @@ -991,7 +1011,7 @@ function MobileView(props: CodingBountiesProps) {
fontFamily: 'Barlow',
marginLeft: '30px'
}}
disabled={payment_pending}
disabled={bountyPending}
hovercolor={color.button_primary.hover}
activecolor={color.button_primary.active}
shadowcolor={color.button_primary.shadow}
Expand Down Expand Up @@ -1172,7 +1192,7 @@ function MobileView(props: CodingBountiesProps) {
}}
text={selectedAward === '' ? 'Skip and Mark Paid' : paidString}
loading={isMarkPaidSaved || updatingPayment}
disabled={payment_pending}
disabled={bountyPending}
endingImg={'/static/mark_paid.svg'}
textStyle={{
width: '130px',
Expand Down

0 comments on commit a27e43d

Please sign in to comment.