8000 add client side validation by thelostone-mc · Pull Request #8723 · gitcoinco/web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add client side validation #8723

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

Merged
merged 4 commits into from
Mar 31, 2021
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
3 changes: 1 addition & 2 deletions app/assets/v2/js/pages/fulfill_bounty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ window. {
}
}
});
};

};
70 changes: 70 additions & 0 deletions app/assets/v2/js/pages/fulfill_bounty/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ fulfillBounty = data => {
_alert({ message: gettext('Add valid address you would want the bounty to be sent to') }, 'error');
unloading_button($('.js-submit'));
return;
} else if (!is_valid_address(data.payoutAddress)) {
$('#payoutAddress-container input').removeClass('valid');
$('#payoutAddress-container input').addClass('invalid');
$('#payoutAddress-container').addClass('invalid');
$('#payoutAddress-container .text-danger').removeClass('hidden');
unloading_button($('.js-submit'));
return;
} else {
$('#payoutAddress-container input').addClass('valid');
$('#payoutAddress-container input').removeClass('invalid');
$('#payoutAddress-container').removeClass('invalid')
$('#payoutAddress-container .text-danger').addClass('hidden');
}

const url = '/api/v1/bounty/fulfill';
Expand Down Expand Up @@ -68,3 +80,61 @@ fulfillBounty = data => {
}
});
};


const is_valid_address = (address) => {
switch (web3_type) {

// etc
// celo
// rsk
// binance

case 'harmony_ext':
if (!address.toLowerCase().startsWith('one')) {
return false;
}
return true;


case 'polkadot_ext':
if (address.toLowerCase().startsWith('0x')) {
return false;
}
return true;


case 'xinfin_ext':
if (!address.toLowerCase().startsWith('xdc')) {
return false;
}
return true;

case 'qr':

if (token_name == 'BTC') {
if (address.toLowerCase().startsWith('0x')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does BTC start with 0x ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is displaying the error when a BTC address starts with 0x 👍

return false;
}
return true;
}

if (token_name == 'FIL') {
if (!address.toLowerCase().startsWith('fil')) {
return false;
}
return true;
}

if (token_name == 'ZIL') {
if (!address.toLowerCase().startsWith('zil')) {
return false;
}
return true;
}

default:
return true;
}

}
13 changes: 7 additions & 6 deletions app/dashboard/templates/bounty/fulfill.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h4 class="text-center mb-4">{% trans "Submit Work" %}</h4>
</div>
{% else %}

<div class="mt-2">
<div id="payoutAddress-container" class="mt-2">
<label class="form__label" for="payoutAddress">{% trans "Payout Address" %}</label>
{% if is_bounties_network or bounty.web3_type == 'web3_modal' %}
<span class="font-weight-semibold" style="cursor: pointer; color: grey; font-size: 10px;">
Expand All @@ -130,11 +130,11 @@ <h4 class="text-center mb-4">{% trans "Submit Work" %}</h4>
<i class='fa fa-info-circle font-smaller-4' data-toggle="tooltip" data-placement="top"
title="Address to which bounty will be sent upon being accepted">
</i>
{% if bounty.metadata.chain_id == '58' %}
<input name='payoutAddress' id='payoutAddress' class="form__input font-body" type="text" placeholder="Polkadot Wallet Address" data-rule-pattern="^(([0-9a-zA-Z]{47})|([0-9a-zA-Z]{48}))"/>
{% else %}
<input name='payoutAddress' id='payoutAddress' class="form__input font-body" type="text" placeholder="0x0000000000000"/>
{% endif %}
<input name='payoutAddress' id='payoutAddress' class="form__input font-body" type="text" placeholder="Enter {{ bounty.token_name }} Wallet Address"/>

<div class="text-danger hidden">
Enter a valid {{ bounty.token_name }} address
</div>
</div>
{% endif %}

Expand Down Expand Up @@ -196,6 +196,7 @@ <h4 class="text-center mb-4">{% trans "Submit Work" %}</h4>

<script>
const web3_type = '{{ bounty.web3_type }}';
const token_name = '{{ bounty.token_name }}';
const is_bounties_network = {% if is_bounties_network|lower == 'false' %} false {% else %} true {% endif %};
</script>
{% include 'shared/analytics.html' %}
Expand Down
0