Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Airdrop/Airdrop.js
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | useEffect(() => { | ||||
} | } | ||||
}, []); | }, []); | ||||
const [formData, setFormData] = useState({ | const [formData, setFormData] = useState({ | ||||
tokenId: '', | tokenId: '', | ||||
totalAirdrop: '', | totalAirdrop: '', | ||||
}); | }); | ||||
const [equalDistributionRatio, setEqualDistributionRatio] = useState(false); | |||||
const [tokenIdIsValid, setTokenIdIsValid] = useState(null); | const [tokenIdIsValid, setTokenIdIsValid] = useState(null); | ||||
const [totalAirdropIsValid, setTotalAirdropIsValid] = useState(null); | const [totalAirdropIsValid, setTotalAirdropIsValid] = useState(null); | ||||
const [airdropRecipients, setAirdropRecipients] = useState(''); | const [airdropRecipients, setAirdropRecipients] = useState(''); | ||||
const [airdropOutputIsValid, setAirdropOutputIsValid] = useState(true); | const [airdropOutputIsValid, setAirdropOutputIsValid] = useState(true); | ||||
const [etokenHolders, setEtokenHolders] = useState(parseInt(0)); | const [etokenHolders, setEtokenHolders] = useState(parseInt(0)); | ||||
const [showAirdropOutputs, setShowAirdropOutputs] = useState(false); | const [showAirdropOutputs, setShowAirdropOutputs] = useState(false); | ||||
const [ignoreOwnAddress, setIgnoreOwnAddress] = useState(false); | const [ignoreOwnAddress, setIgnoreOwnAddress] = useState(false); | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | const calculateXecAirdrop = async () => { | ||||
passLoadingStatus(false); | passLoadingStatus(false); | ||||
return; | return; | ||||
} | } | ||||
// if the ignore minimum payment threshold option is enabled | // if the ignore minimum payment threshold option is enabled | ||||
if (ignoreRecipientsBelowDust) { | if (ignoreRecipientsBelowDust) { | ||||
// minimum airdrop threshold | // minimum airdrop threshold | ||||
const minEligibleAirdrop = fromSatoshisToXec(currency.dustSats); | const minEligibleAirdrop = fromSatoshisToXec(currency.dustSats); | ||||
// first calculation on expected pro rata airdrops | |||||
let initialTotalTokenAmongstRecipients = new BigNumber(0); | let initialTotalTokenAmongstRecipients = new BigNumber(0); | ||||
let initialTotalHolders = new BigNumber(airdropList.size); // amount of addresses that hold this eToken | let initialTotalHolders = new BigNumber(airdropList.size); // amount of addresses that hold this eToken | ||||
setEtokenHolders(initialTotalHolders); | setEtokenHolders(initialTotalHolders); | ||||
// keep a cumulative total of each eToken holding in each address in airdropList | // keep a cumulative total of each eToken holding in each address in airdropList | ||||
airdropList.forEach( | airdropList.forEach( | ||||
index => | index => | ||||
(initialTotalTokenAmongstRecipients = | (initialTotalTokenAmongstRecipients = | ||||
Show All 38 Lines | const calculateXecAirdrop = async () => { | ||||
// keep a cumulative total of each eToken holding in each address in airdropList | // keep a cumulative total of each eToken holding in each address in airdropList | ||||
airdropList.forEach( | airdropList.forEach( | ||||
index => | index => | ||||
(totalTokenAmongstRecipients = totalTokenAmongstRecipients.plus( | (totalTokenAmongstRecipients = totalTokenAmongstRecipients.plus( | ||||
new BigNumber(index), | new BigNumber(index), | ||||
)), | )), | ||||
); | ); | ||||
let circToAirdropRatio = new BigNumber(formData.totalAirdrop).div( | let circToAirdropRatio = new BigNumber(0); | ||||
totalTokenAmongstRecipients, | |||||
); | |||||
let resultString = ''; | let resultString = ''; | ||||
// generate the resulting recipients list based on distribution ratio | |||||
if (equalDistributionRatio) { | |||||
const equalDividend = new BigNumber( | |||||
formData.totalAirdrop, | |||||
).dividedBy(new BigNumber(totalHolders)); | |||||
airdropList.forEach( | |||||
(element, index) => | |||||
(resultString += | |||||
convertEtokenToEcashAddr(index) + | |||||
',' + | |||||
equalDividend.decimalPlaces(currency.cashDecimals) + | |||||
'\n'), | |||||
); | |||||
} else { | |||||
circToAirdropRatio = new BigNumber(formData.totalAirdrop).div( | |||||
totalTokenAmongstRecipients, | |||||
); | |||||
airdropList.forEach( | airdropList.forEach( | ||||
(element, index) => | (element, index) => | ||||
(resultString += | (resultString += | ||||
convertEtokenToEcashAddr(index) + | convertEtokenToEcashAddr(index) + | ||||
',' + | ',' + | ||||
new BigNumber(element) | new BigNumber(element) | ||||
.multipliedBy(circToAirdropRatio) | .multipliedBy(circToAirdropRatio) | ||||
.decimalPlaces(currency.cashDecimals) + | .decimalPlaces(currency.cashDecimals) + | ||||
'\n'), | '\n'), | ||||
); | ); | ||||
} | |||||
resultString = resultString.substring(0, resultString.length - 1); // remove the final newline | resultString = resultString.substring(0, resultString.length - 1); // remove the final newline | ||||
setAirdropRecipients(resultString); | setAirdropRecipients(resultString); | ||||
setAirdropCalcModalProgress(100); | setAirdropCalcModalProgress(100); | ||||
if (!resultString) { | if (!resultString) { | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | return ( | ||||
onChange={e => | onChange={e => | ||||
handleTotalAirdropInput(e) | handleTotalAirdropInput(e) | ||||
} | } | ||||
/> | /> | ||||
</Form.Item> | </Form.Item> | ||||
<Form.Item> | <Form.Item> | ||||
<AirdropOptions> | <AirdropOptions> | ||||
<Switch | <Switch | ||||
checkedChildren="Equal" | |||||
unCheckedChildren="Pro-Rata" | |||||
defaultunchecked="true" | |||||
checked={equalDistributionRatio} | |||||
onChange={() => { | |||||
setEqualDistributionRatio( | |||||
prev => !prev, | |||||
); | |||||
}} | |||||
/> | |||||
</AirdropOptions> | |||||
</Form.Item> | |||||
<Form.Item> | |||||
<AirdropOptions> | |||||
<Switch | |||||
onChange={() => | onChange={() => | ||||
handleIgnoreOwnAddress( | handleIgnoreOwnAddress( | ||||
prev => !prev, | prev => !prev, | ||||
) | ) | ||||
} | } | ||||
defaultunchecked="true" | defaultunchecked="true" | ||||
checked={ignoreOwnAddress} | checked={ignoreOwnAddress} | ||||
/> | /> | ||||
▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines |