Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#778, #729 default gateway & slider amount delegation changes bug fix #789

Merged
merged 3 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PORT=3010
NODE_PATH=src/
REACT_APP_ENVIRONMENT=localhost
27 changes: 20 additions & 7 deletions src/components/DelegateButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DelegateButton extends Component {
objectsToDelegateToMilestone: [],
modalVisible: false,
amount: '0',
amountSelected: '0',
maxAmount: new BigNumber('0'),
curProjectId: null,
};
Expand All @@ -97,7 +98,7 @@ class DelegateButton extends Component {
});
}

selectedObject(type, { target }) {
selectedObject(type, { target }, amountSelected) {
const admin = this.props.types.find(t => t._id === target.value[0]);

let maxAmount = this.props.donation.amountRemaining;
Expand All @@ -109,10 +110,16 @@ class DelegateButton extends Component {
maxAmount = maxDelegationAmount;
}
}
let tempAmount = 0;
if (amountSelected !== 0) {
tempAmount = amountSelected;
} else {
tempAmount = maxAmount.toFixed();
}

this.setState({
maxAmount,
amount: maxAmount.toFixed(),
amount: tempAmount,
objectsToDelegateToCampaign: target.value,
});
if (type === Milestone.type) {
Expand All @@ -121,7 +128,6 @@ class DelegateButton extends Component {
this.setState({
curProjectId: admin ? admin.projectId : null,
objectsToDelegateToCampaign: target.value,
objectsToDelegateToMilestone: [],
});
}
}
Expand Down Expand Up @@ -297,7 +303,7 @@ class DelegateButton extends Component {
placeholder="Select a Campaign"
value={campaignValue}
options={milestoneOnly ? milestoneOnlyCampaignTypes : campaignTypes}
onSelect={v => this.selectedObject(Campaign.type, v)}
onSelect={v => this.selectedObject(Campaign.type, v, this.state.amountSelected)}
maxLength={1}
/>
<InputToken
Expand All @@ -306,7 +312,7 @@ class DelegateButton extends Component {
placeholder="Select a Milestone"
value={objectsToDelegateToMilestone}
options={milestoneTypes}
onSelect={v => this.selectedObject(Milestone.type, v)}
onSelect={v => this.selectedObject(Milestone.type, v, this.state.amountSelected)}
/>
</div>
</div>
Expand All @@ -326,7 +332,12 @@ class DelegateButton extends Component {
[maxAmount.toNumber()]: maxAmount.toFixed(),
}}
tooltip={false}
onChange={amount => this.setState({ amount: Number(amount).toFixed(2) })}
onChange={amount =>
this.setState({
amount: Number(amount).toFixed(2),
amountSelected: Number(amount).toFixed(2),
})
}
/>
</div>

Expand All @@ -341,7 +352,9 @@ class DelegateButton extends Component {
}}
name="amount"
value={this.state.amount}
onChange={amount => this.setState({ amount })}
onChange={amount =>
this.setState({ amount }, this.setState({ amountSelected: amount }))
}
/>
</div>

Expand Down
32 changes: 24 additions & 8 deletions src/components/DelegateMultipleButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class DelegateMultipleButton extends Component {
modalVisible: false,
delegations: [],
maxAmount: new BigNumber('0'),
selectedAmount: new BigNumber('0'),
delegationOptions: [],
objectToDelegateFrom: [],
tokenWhitelistOptions: props.tokenWhitelist.map(t => ({
Expand Down Expand Up @@ -117,7 +118,10 @@ class DelegateMultipleButton extends Component {

this.setState({ delegationOptions }, () => {
if (delegationOptions.length === 1) {
this.selectedObject({ target: { value: [delegationOptions[0].id] } });
this.selectedObject(
{ target: { value: [delegationOptions[0].id] } },
new BigNumber(0),
);
}
});
},
Expand All @@ -135,13 +139,13 @@ class DelegateMultipleButton extends Component {
);
}

selectedObject({ target }) {
selectedObject({ target }, selectedAmount) {
this.setState({ objectToDelegateFrom: target.value, isLoadingDonations: true });

this.loadDonations(target.value);
this.loadDonations(target.value, selectedAmount);
}

loadDonations(ids) {
loadDonations(ids, selectedAmount) {
if (ids.length !== 1) return;

const entity = this.state.delegationOptions.find(c => c.id === ids[0]);
Expand Down Expand Up @@ -189,6 +193,12 @@ class DelegateMultipleButton extends Component {
new BigNumber('0'),
);

const localMax = amount;

if (selectedAmount.toNumber() !== 0) {
amount = selectedAmount;
}

if (this.props.milestone && this.props.milestone.isCapped) {
const maxDonationAmount = this.props.milestone.maxAmount.minus(
this.props.milestone.currentBalance,
Expand All @@ -199,9 +209,9 @@ class DelegateMultipleButton extends Component {

this.setState({
delegations,
maxAmount: amount,
amount: amount.toFixed(),
maxAmount: localMax,
isLoadingDonations: false,
amount,
});
},
() => this.setState({ isLoadingDonations: false }),
Expand Down Expand Up @@ -333,7 +343,7 @@ class DelegateMultipleButton extends Component {
placeholder={milestone ? 'Select a DAC or Campaign' : 'Select a DAC'}
value={this.state.objectToDelegateFrom}
options={delegationOptions}
onSelect={this.selectedObject}
onSelect={v => this.selectedObject(v, this.state.selectedAmount)}
maxLength={1}
/>
</div>
Expand Down Expand Up @@ -388,6 +398,7 @@ class DelegateMultipleButton extends Component {
amount: prevState.maxAmount.gte(newAmount)
? newAmount.toFixed(2)
: prevState.maxAmount.toFixed(2),
selectedAmount: new BigNumber(newAmount),
}))
}
/>
Expand All @@ -404,7 +415,12 @@ class DelegateMultipleButton extends Component {
}}
name="amount"
value={amount}
onChange={(name, newAmount) => this.setState({ amount: newAmount })}
onChange={(name, newAmount) =>
this.setState({
amount: newAmount,
selectedAmount: new BigNumber(newAmount),
})
}
/>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const configurations = {
foreignNetworkId: 4,
homeNetworkName: 'Mainnet',
homeNetworkId: 1,
ipfsGateway: 'https://giveth.ipfs.alibre.io/ipfs/',
ipfsGateway: 'https://ipfs.giveth.io/ipfs/',
analytics: {
ga_UA: 'UA-103956937-2',
useGoogleAnalytics: true,
Expand Down