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

Integrate project currency to Send Bonuses feature #844

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion srcv2/components/SendBonus.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const SendBonus = (props) => {
const [bonusPayments, setBonusPayments] = useState([])
const [selectedBonusSplitType, setSelectedBonusSplitType] = useState(0)
const [sentBonuses, setSentBonuses] = useState(0)
const [selectedCurrency, setSelectedCurrency] = useState('s ')

const buttonText = ['Continue', 'Send bonuses', 'Finish']

Expand All @@ -34,7 +35,7 @@ const SendBonus = (props) => {
throw new Error('User does not have a wallet setup')
}
if (bp.contributor.wallet.invoice_macaroon != null || bp.contributor.wallet.onchain_address != null) {
contributorsWithWallets.push({ contributor_id: bp.contributor.id, amount_to_pay: Math.round(bp.satsBonusAmount) })
contributorsWithWallets.push({ contributor_id: bp.contributor.id, amount_to_pay: Math.round(selectedCurrency == 's ' ? bp.amount : bp.satsBonusAmount) })
}
} catch (error) {
console.log('An error occurred: ' + error)
Expand Down Expand Up @@ -124,17 +125,21 @@ const SendBonus = (props) => {
setBonusPayments={setBonusPayments}
selectedBonusSplitType={selectedBonusSplitType}
setSelectedBonusSplitType={setSelectedBonusSplitType}
selectedCurrency={selectedCurrency}
setSelectedCurrency={setSelectedCurrency}
/>
}
{screenIndex == 1 &&
<SendBonusConfirmation
bonusPayments={bonusPayments}
selectedBonusSplitType={selectedBonusSplitType}
selectedCurrency={selectedCurrency}
/>
}
{screenIndex == 2 &&
<SendBonusSuccessful
sentBonuses={sentBonuses}
selectedCurrency={selectedCurrency}
/>
}
<div className='grid absolute bottom-10 left-16 right-16 gap-2'>
Expand Down
6 changes: 5 additions & 1 deletion srcv2/components/SendBonusAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const SendBonusAmount = (props) => {
bonusPayments,
setBonusPayments,
selectedBonusSplitType,
setSelectedBonusSplitType
setSelectedBonusSplitType,
selectedCurrency,
setSelectedCurrency
} = props

return (
Expand Down Expand Up @@ -60,6 +62,8 @@ const SendBonusAmount = (props) => {
setSelectedContributors={setSelectedContributors}
bonusAmount={bonusAmount}
setBonusAmount={setBonusAmount}
selectedCurrency={selectedCurrency}
setSelectedCurrency={setSelectedCurrency}
/>
) : (
<SendBonusCustomize
Expand Down
29 changes: 20 additions & 9 deletions srcv2/components/SendBonusConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const SendBonusConfirmation = (props) => {

const {
bonusPayments,
selectedBonusSplitType
selectedBonusSplitType,
selectedCurrency
} = props

const renderSenders = () => {
Expand All @@ -21,11 +22,16 @@ const SendBonusConfirmation = (props) => {
</div>
<div className='grid grid-cols-1 text-right'>
<p className='font-bold'>
{`${Intl.NumberFormat().format(Math.trunc(bp.satsBonusAmount))} SATS`}
</p>
<p className='text-gray'>
{`${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bp.amount))}`}
{selectedCurrency == 's '
? `${Intl.NumberFormat().format(Math.trunc(bp.amount))} SATS`
: `${Intl.NumberFormat().format(Math.trunc(bp.satsBonusAmount))} SATS`
}
</p>
{selectedCurrency != 's ' &&
<p className='text-gray'>
{`${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bp.amount))}`}
</p>
}
</div>
</div>
)
Expand All @@ -46,11 +52,16 @@ const SendBonusConfirmation = (props) => {
{selectedBonusSplitType == 0 &&
<>
<p className='text-center text-4xl'>
{`${Intl.NumberFormat().format(Math.trunc(bonusPayments[0].satsBonusAmount))} SATS`}
{selectedCurrency == 's '
? `${Intl.NumberFormat().format(Math.trunc(bonusPayments[0].amount))} SATS`
: `${Intl.NumberFormat().format(Math.trunc(bonusPayments[0].satsBonusAmount))} SATS`
}
</p>
<p className='text-center text-md text-gray'>
{`~ ${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bonusPayments[0].amount))}`}
</p>
{selectedCurrency != 's ' &&
<p className='text-center text-md text-gray'>
{`~ ${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bonusPayments[0].amount))}`}
</p>
}
</>
}
<p className='font-bold text-md text-gray'>
Expand Down
32 changes: 24 additions & 8 deletions srcv2/components/SendBonusEqualy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ const SendBonusEqualy = (props) => {
const {
setSelectedContributors,
project,
setBonusAmount
setBonusAmount,
selectedCurrency,
setSelectedCurrency
} = props

const [selectedContributorsIdx, setSelectedContributorsIdx] = useState([])

const currencyInformation = selectCurrencyInformation({
currency: project.expected_budget_currency
? project.expected_budget_currency
: 'SATS'
})

useEffect(() => {
const contributors = project.contributors.filter((c, idx) => selectedContributorsIdx.includes(idx))
setSelectedContributors(contributors)
}, [selectedContributorsIdx])

const currencyInformation =
selectCurrencyInformation({
currency: 'USD'
})

const selectContributor = (idx) => {
if (selectedContributorsIdx.includes(idx)) {
setSelectedContributorsIdx(
Expand Down Expand Up @@ -73,18 +76,31 @@ const SendBonusEqualy = (props) => {

return (
<div className='SendBonusEqualy'>
<div className='mt-10'>
<div className='flex mt-10 items-center'>
<CurrencyTextField
fullWidth
label='Payment amount'
variant='outlined'
currencySymbol={`${currencyInformation['symbol']}`}
currencySymbol={`${selectedCurrency}`}
minimumValue='0'
outputFormat='string'
decimalCharacter={`${currencyInformation['decimal']}`}
digitGroupSeparator={`${currencyInformation['thousand']}`}
onChange={(event) => handleBonusAmountChange(event.target.value)}
/>
<button
className='ml-3 bg-setlife text-black rounded-full p-2 flex items-center justify-center'
type='button'
onClick={() => setSelectedCurrency(selectedCurrency == 's '
? currencyInformation.symbol
: 's ')
}
>
{selectedCurrency == currencyInformation.symbol
? <img className='w-7' src='https://project-trinary.s3.amazonaws.com/images/Satoshi+regular+black+2.png' alt='satoshi' />
: <p className='w-6'>{currencyInformation.symbol}</p>
}
</button>
</div>
<div className='mt-10'>
<p className='font-bold text-md mb-4'>
Expand Down
27 changes: 20 additions & 7 deletions srcv2/components/SendBonusSuccessful.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
const SendBonusSuccessful = (props) => {

const {
sentBonuses
sentBonuses,
selectedCurrency
} = props

const renderSuccessfulTransactions = (payments) => {
Expand All @@ -20,11 +21,16 @@ const SendBonusSuccessful = (props) => {
</div>
<div className='grid grid-cols-1 text-right'>
<p className='font-bold'>
{`${Intl.NumberFormat().format(Math.trunc(bp.satsBonusAmount))} SATS`}
</p>
<p className='text-gray'>
{`${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bp.amount))}`}
{selectedCurrency == 's '
? `${Intl.NumberFormat().format(Math.trunc(bp.amount))} SATS`
: `${Intl.NumberFormat().format(Math.trunc(bp.satsBonusAmount))} SATS`
}
</p>
{selectedCurrency != 's ' &&
<p className='text-center text-md text-gray'>
{`${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bp.amount))}`}
</p>
}
</div>
</div>
)
Expand All @@ -42,10 +48,17 @@ const SendBonusSuccessful = (props) => {
</div>
<div className='grid grid-cols-1 text-right'>
<p className='font-bold'>
{`${Intl.NumberFormat().format(Math.trunc(bp.satsBonusAmount))} SATS`}
{selectedCurrency == 's '
? `${Intl.NumberFormat().format(Math.trunc(bp.amount))} SATS`
: `${Intl.NumberFormat().format(Math.trunc(bp.satsBonusAmount))} SATS`
}
</p>
<p className='text-gray'>
{`${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bp.amount))}`}
{selectedCurrency != 's ' &&
<p className='text-center text-md text-gray'>
{`${Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(Math.trunc(bp.amount))}`}
</p>
}
</p>
</div>
</div>
Expand Down