2019-02-16 08:49:32 -08:00
|
|
|
|
import React from 'react';
|
|
|
|
|
import { Form, Input, Button, message } from 'antd';
|
2019-11-13 15:44:35 -08:00
|
|
|
|
import { updateUserSettings } from 'api/api';
|
2019-02-16 08:49:32 -08:00
|
|
|
|
import { isValidAddress } from 'utils/validators';
|
2019-11-13 15:44:35 -08:00
|
|
|
|
import { UserSettings } from 'types';
|
2019-02-16 08:49:32 -08:00
|
|
|
|
|
2019-11-13 15:44:35 -08:00
|
|
|
|
interface Props {
|
|
|
|
|
userSettings?: UserSettings;
|
|
|
|
|
isFetching: boolean;
|
|
|
|
|
errorFetching: boolean;
|
2019-02-16 08:49:32 -08:00
|
|
|
|
userid: number;
|
2019-11-13 15:44:35 -08:00
|
|
|
|
onAddressSet: (refundAddress: UserSettings['refundAddress']) => void;
|
2019-02-16 08:49:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 15:44:35 -08:00
|
|
|
|
interface State {
|
CCRs (#86)
* CCRs API / Models boilerplate
* start on frontend
* backendy things
* Create CCR redux module, integrate API endpoints, create types
* Fix/Cleanup API
* Wire up CreateRequestDraftList
* bounty->target
* Add 'Create Request Flow' MVP
* cleanup
* Tweak filenames
* Simplify migrations
* fix migrations
* CCR Staking MVP
* tslint
* Get Pending Requests into Profile
* Remove staking requirement
* more staking related removals
* MVP Admin integration
* Make RFP when CCR is accepted
* Add pagination to CCRs in Admin
Improve styles for Proposals
* Hookup notifications
Adjust copy
* Simplify ccr->rfp relationship
Add admin approval email
Fixup copy
* Show Message on RFP Detail
Make Header CTAs change based on draft status
Adjust proposal card style
* Bugfix: Show header for non signed in users
* Add 'create a request' to intro
* Profile Created CCRs
RFP CCR attribution
* ignore
* CCR Price in USD (#85)
* init profile tipjar backend
* init profile tipjar frontend
* fix lint
* implement tip jar block
* fix wrapping, hide tip block on self
* init backend proposal tipjar
* init frontend proposal tipjar
* add hide title, fix bug
* uncomment rate limit
* rename vars, use null check
* allow address and view key to be unset
* add api tests
* fix tsc errors
* fix lint
* fix CopyInput styling
* fix migrations
* hide tipping in proposal if address not set
* add tip address to create flow
* redesign campaign block
* fix typo
* init backend changes
* init admin changes
* init frontend changes
* fix backend tests
* update campaign block
* be - init rfp usd changes
* admin - init rfp usd changes
* fe - fully adapt api util functions to usd
* fe - init rfp usd changes
* adapt profile created to usd
* misc usd changes
* add tip jar to dedicated card
* fix tipjar bug
* use zf light logo
* switch to zf grants logo
* hide profile tip jar if address not set
* add comment, run prettier
* conditionally add info icon and tooltip to funding line
* admin - disallow decimals in RFPs
* fe - cover usd string edge case
* add Usd as rfp bounty type
* fix migration order
* fix email bug
* adapt CCRs to USD
* implement CCR preview
* fix tsc
* Copy Updates and UX Tweaks (#87)
* Add default structure to proposal content
* Landing page copy
* Hide contributors tab for v2 proposals
* Minor UX tweaks for Liking/Following/Tipping
* Copy for Tipping Tooltip, proposal explainer for review, and milestone day estimate notice.
* Fix header styles bug and remove commented out styles.
* Revert "like" / "unfollow" hyphenication
* Comment out unused tests related to staking
Increase PROPOSAL_TARGET_MAX in .env.example
* Comment out ccr approval email send until ready
* Adjust styles, copy.
* fix proposal prune test (#88)
* fix USD display in preview, fix non-unique key (#90)
* Pre-stepper explainer for CCRs.
* Tweak styles
* Default content for CCRs
* fix tsc
* CCR approval and rejection emails
* add back admin_approval_ccr email templates
* Link ccr author name to profile in RFPs
* copy tweaks
* copy tweak
* hookup mangle user command
* Fix/add endif in jinja
* fix tests
* review
* fix review
2019-12-05 17:01:02 -08:00
|
|
|
|
isSaving: boolean;
|
|
|
|
|
refundAddress: string | null;
|
|
|
|
|
refundAddressSet: string | null;
|
2019-11-13 15:44:35 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class RefundAddress extends React.Component<Props, State> {
|
|
|
|
|
static getDerivedStateFromProps(nextProps: Props, prevState: State) {
|
|
|
|
|
const { userSettings } = nextProps;
|
|
|
|
|
const { refundAddress, refundAddressSet } = prevState;
|
2019-02-16 08:49:32 -08:00
|
|
|
|
|
2019-11-13 15:44:35 -08:00
|
|
|
|
const ret: Partial<State> = {};
|
|
|
|
|
|
|
|
|
|
if (!userSettings || !userSettings.refundAddress) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-02-16 08:49:32 -08:00
|
|
|
|
|
2019-11-13 15:44:35 -08:00
|
|
|
|
if (userSettings.refundAddress !== refundAddressSet) {
|
|
|
|
|
ret.refundAddressSet = userSettings.refundAddress;
|
2019-02-16 08:49:32 -08:00
|
|
|
|
|
2019-11-13 15:44:35 -08:00
|
|
|
|
if (refundAddress === null) {
|
|
|
|
|
ret.refundAddress = userSettings.refundAddress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
2019-02-16 08:49:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
CCRs (#86)
* CCRs API / Models boilerplate
* start on frontend
* backendy things
* Create CCR redux module, integrate API endpoints, create types
* Fix/Cleanup API
* Wire up CreateRequestDraftList
* bounty->target
* Add 'Create Request Flow' MVP
* cleanup
* Tweak filenames
* Simplify migrations
* fix migrations
* CCR Staking MVP
* tslint
* Get Pending Requests into Profile
* Remove staking requirement
* more staking related removals
* MVP Admin integration
* Make RFP when CCR is accepted
* Add pagination to CCRs in Admin
Improve styles for Proposals
* Hookup notifications
Adjust copy
* Simplify ccr->rfp relationship
Add admin approval email
Fixup copy
* Show Message on RFP Detail
Make Header CTAs change based on draft status
Adjust proposal card style
* Bugfix: Show header for non signed in users
* Add 'create a request' to intro
* Profile Created CCRs
RFP CCR attribution
* ignore
* CCR Price in USD (#85)
* init profile tipjar backend
* init profile tipjar frontend
* fix lint
* implement tip jar block
* fix wrapping, hide tip block on self
* init backend proposal tipjar
* init frontend proposal tipjar
* add hide title, fix bug
* uncomment rate limit
* rename vars, use null check
* allow address and view key to be unset
* add api tests
* fix tsc errors
* fix lint
* fix CopyInput styling
* fix migrations
* hide tipping in proposal if address not set
* add tip address to create flow
* redesign campaign block
* fix typo
* init backend changes
* init admin changes
* init frontend changes
* fix backend tests
* update campaign block
* be - init rfp usd changes
* admin - init rfp usd changes
* fe - fully adapt api util functions to usd
* fe - init rfp usd changes
* adapt profile created to usd
* misc usd changes
* add tip jar to dedicated card
* fix tipjar bug
* use zf light logo
* switch to zf grants logo
* hide profile tip jar if address not set
* add comment, run prettier
* conditionally add info icon and tooltip to funding line
* admin - disallow decimals in RFPs
* fe - cover usd string edge case
* add Usd as rfp bounty type
* fix migration order
* fix email bug
* adapt CCRs to USD
* implement CCR preview
* fix tsc
* Copy Updates and UX Tweaks (#87)
* Add default structure to proposal content
* Landing page copy
* Hide contributors tab for v2 proposals
* Minor UX tweaks for Liking/Following/Tipping
* Copy for Tipping Tooltip, proposal explainer for review, and milestone day estimate notice.
* Fix header styles bug and remove commented out styles.
* Revert "like" / "unfollow" hyphenication
* Comment out unused tests related to staking
Increase PROPOSAL_TARGET_MAX in .env.example
* Comment out ccr approval email send until ready
* Adjust styles, copy.
* fix proposal prune test (#88)
* fix USD display in preview, fix non-unique key (#90)
* Pre-stepper explainer for CCRs.
* Tweak styles
* Default content for CCRs
* fix tsc
* CCR approval and rejection emails
* add back admin_approval_ccr email templates
* Link ccr author name to profile in RFPs
* copy tweaks
* copy tweak
* hookup mangle user command
* Fix/add endif in jinja
* fix tests
* review
* fix review
2019-12-05 17:01:02 -08:00
|
|
|
|
state: State = {
|
2019-11-13 15:44:35 -08:00
|
|
|
|
isSaving: false,
|
|
|
|
|
refundAddress: null,
|
CCRs (#86)
* CCRs API / Models boilerplate
* start on frontend
* backendy things
* Create CCR redux module, integrate API endpoints, create types
* Fix/Cleanup API
* Wire up CreateRequestDraftList
* bounty->target
* Add 'Create Request Flow' MVP
* cleanup
* Tweak filenames
* Simplify migrations
* fix migrations
* CCR Staking MVP
* tslint
* Get Pending Requests into Profile
* Remove staking requirement
* more staking related removals
* MVP Admin integration
* Make RFP when CCR is accepted
* Add pagination to CCRs in Admin
Improve styles for Proposals
* Hookup notifications
Adjust copy
* Simplify ccr->rfp relationship
Add admin approval email
Fixup copy
* Show Message on RFP Detail
Make Header CTAs change based on draft status
Adjust proposal card style
* Bugfix: Show header for non signed in users
* Add 'create a request' to intro
* Profile Created CCRs
RFP CCR attribution
* ignore
* CCR Price in USD (#85)
* init profile tipjar backend
* init profile tipjar frontend
* fix lint
* implement tip jar block
* fix wrapping, hide tip block on self
* init backend proposal tipjar
* init frontend proposal tipjar
* add hide title, fix bug
* uncomment rate limit
* rename vars, use null check
* allow address and view key to be unset
* add api tests
* fix tsc errors
* fix lint
* fix CopyInput styling
* fix migrations
* hide tipping in proposal if address not set
* add tip address to create flow
* redesign campaign block
* fix typo
* init backend changes
* init admin changes
* init frontend changes
* fix backend tests
* update campaign block
* be - init rfp usd changes
* admin - init rfp usd changes
* fe - fully adapt api util functions to usd
* fe - init rfp usd changes
* adapt profile created to usd
* misc usd changes
* add tip jar to dedicated card
* fix tipjar bug
* use zf light logo
* switch to zf grants logo
* hide profile tip jar if address not set
* add comment, run prettier
* conditionally add info icon and tooltip to funding line
* admin - disallow decimals in RFPs
* fe - cover usd string edge case
* add Usd as rfp bounty type
* fix migration order
* fix email bug
* adapt CCRs to USD
* implement CCR preview
* fix tsc
* Copy Updates and UX Tweaks (#87)
* Add default structure to proposal content
* Landing page copy
* Hide contributors tab for v2 proposals
* Minor UX tweaks for Liking/Following/Tipping
* Copy for Tipping Tooltip, proposal explainer for review, and milestone day estimate notice.
* Fix header styles bug and remove commented out styles.
* Revert "like" / "unfollow" hyphenication
* Comment out unused tests related to staking
Increase PROPOSAL_TARGET_MAX in .env.example
* Comment out ccr approval email send until ready
* Adjust styles, copy.
* fix proposal prune test (#88)
* fix USD display in preview, fix non-unique key (#90)
* Pre-stepper explainer for CCRs.
* Tweak styles
* Default content for CCRs
* fix tsc
* CCR approval and rejection emails
* add back admin_approval_ccr email templates
* Link ccr author name to profile in RFPs
* copy tweaks
* copy tweak
* hookup mangle user command
* Fix/add endif in jinja
* fix tests
* review
* fix review
2019-12-05 17:01:02 -08:00
|
|
|
|
refundAddressSet: null,
|
|
|
|
|
};
|
2019-11-13 15:44:35 -08:00
|
|
|
|
|
2019-02-16 08:49:32 -08:00
|
|
|
|
render() {
|
2019-11-13 15:44:35 -08:00
|
|
|
|
const { isSaving, refundAddress, refundAddressSet } = this.state;
|
|
|
|
|
const { isFetching, errorFetching } = this.props;
|
|
|
|
|
const addressChanged = refundAddress !== refundAddressSet;
|
2019-02-16 08:49:32 -08:00
|
|
|
|
|
|
|
|
|
let status: 'validating' | 'error' | undefined;
|
|
|
|
|
let help;
|
|
|
|
|
if (isFetching) {
|
|
|
|
|
status = 'validating';
|
|
|
|
|
} else if (refundAddress && !isValidAddress(refundAddress)) {
|
|
|
|
|
status = 'error';
|
|
|
|
|
help = 'That doesn’t look like a valid address';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form className="RefundAddress" layout="vertical" onSubmit={this.handleSubmit}>
|
|
|
|
|
<Form.Item label="Refund address" validateStatus={status} help={help}>
|
|
|
|
|
<Input
|
2019-11-13 15:44:35 -08:00
|
|
|
|
value={refundAddress || ''}
|
2019-12-10 12:22:40 -08:00
|
|
|
|
placeholder="Z address"
|
2019-02-16 08:49:32 -08:00
|
|
|
|
onChange={this.handleChange}
|
2019-11-13 15:44:35 -08:00
|
|
|
|
disabled={isFetching || isSaving || errorFetching}
|
2019-02-16 08:49:32 -08:00
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
htmlType="submit"
|
|
|
|
|
size="large"
|
2019-11-13 15:44:35 -08:00
|
|
|
|
disabled={
|
|
|
|
|
!refundAddress || isSaving || !!status || errorFetching || !addressChanged
|
|
|
|
|
}
|
2019-02-16 08:49:32 -08:00
|
|
|
|
loading={isSaving}
|
|
|
|
|
block
|
|
|
|
|
>
|
|
|
|
|
Change refund address
|
|
|
|
|
</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
this.setState({ refundAddress: ev.currentTarget.value });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private handleSubmit = async (ev: React.FormEvent<HTMLFormElement>) => {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
const { userid } = this.props;
|
|
|
|
|
const { refundAddress } = this.state;
|
|
|
|
|
if (!refundAddress) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setState({ isSaving: true });
|
|
|
|
|
try {
|
|
|
|
|
const res = await updateUserSettings(userid, { refundAddress });
|
|
|
|
|
message.success('Settings saved');
|
2019-11-13 15:44:35 -08:00
|
|
|
|
const refundAddressNew = res.data.refundAddress || '';
|
|
|
|
|
this.setState({ refundAddress: refundAddressNew });
|
|
|
|
|
this.props.onAddressSet(refundAddressNew);
|
2019-02-16 08:49:32 -08:00
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
message.error(err.message || err.toString(), 5);
|
|
|
|
|
}
|
|
|
|
|
this.setState({ isSaving: false });
|
|
|
|
|
};
|
|
|
|
|
}
|