Gradually replace default tips with user-defined ones on long press (up to 7) (#2069)

* commented the lines to make sure dupes are also checked on subdomains

* chore: fix lint issues

* add more than 3 custom tips, up to 7 total

* fix merge issue

* shorten logic

* don't check length for slice without need

---------

Co-authored-by: 김현희 <pygmal@gimhyeonhuiui-MacBookAir.local>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
This commit is contained in:
nl 2025-04-08 08:21:51 +09:00 committed by GitHub
parent 1835a8f255
commit af096a08a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,7 +18,10 @@ import { useSendWallets } from '@/wallets/index'
const defaultTips = [100, 1000, 10_000, 100_000] const defaultTips = [100, 1000, 10_000, 100_000]
const Tips = ({ setOValue }) => { const Tips = ({ setOValue }) => {
const tips = [...getCustomTips(), ...defaultTips].sort((a, b) => a - b) const customTips = getCustomTips()
const defaultNoCustom = defaultTips.filter(d => !customTips.includes(d))
const tips = [...customTips, ...defaultNoCustom].slice(0, 7).sort((a, b) => a - b)
return tips.map((num, i) => return tips.map((num, i) =>
<Button <Button
size='sm' size='sm'
@ -37,11 +40,7 @@ const Tips = ({ setOValue }) => {
const getCustomTips = () => JSON.parse(window.localStorage.getItem('custom-tips')) || [] const getCustomTips = () => JSON.parse(window.localStorage.getItem('custom-tips')) || []
const addCustomTip = (amount) => { const addCustomTip = (amount) => {
if (defaultTips.includes(amount)) return const customTips = Array.from(new Set([amount, ...getCustomTips()])).slice(0, 7)
let customTips = Array.from(new Set([amount, ...getCustomTips()]))
if (customTips.length > 3) {
customTips = customTips.slice(0, 3)
}
window.localStorage.setItem('custom-tips', JSON.stringify(customTips)) window.localStorage.setItem('custom-tips', JSON.stringify(customTips))
} }