Skip to content

Commit 23a5ca0

Browse files
committed
Start adding native token delegation
1 parent 92b12e6 commit 23a5ca0

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

apps/web/src/screens/Manage.tsx

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Dialog,
55
Heading,
66
PlusSVG,
7+
RightArrowSVG,
78
Spinner,
89
Typography,
910
} from '@ensdomains/thorin'
@@ -133,7 +134,7 @@ export function Manage() {
133134
navigate('/strategy')
134135
}
135136

136-
function handleUpdate() {
137+
function handleMultiDelegate() {
137138
if (!address) return
138139

139140
if (allocatedDelegates.map((del) => del[0]).includes(address)) {
@@ -366,6 +367,19 @@ export function Manage() {
366367
>
367368
Add delegate
368369
</Button>
370+
371+
{/* <Button
372+
prefix={<PlusSVG />}
373+
onClick={() => {
374+
write.writeContract({
375+
...ensTokenContract,
376+
functionName: 'delegate',
377+
args: [address!],
378+
})
379+
}}
380+
>
381+
Delegate all tokens natively
382+
</Button> */}
369383
</ButtonWrapper>
370384

371385
{receipt.isSuccess && (
@@ -452,13 +466,60 @@ export function Manage() {
452466
>
453467
<Dialog.CloseButton onClick={() => setIsConfirmationModalOpen(false)} />
454468

455-
<div className="w-[28rem] max-w-full text-center">
456-
<Typography>
457-
When you delegate your $ENS tokens they will be swapped for NFTs
458-
that represent each delegate. You can swap back to your tokens
459-
anytime by undelegating.
460-
</Typography>
461-
</div>
469+
{(() => {
470+
console.log({ delegatesArr, allocatedDelegates, changingDelegates })
471+
console.log(
472+
'new balance of first delegate',
473+
allocatedDelegates[0]?.[1]?.newBalance
474+
)
475+
476+
// 95% of token balance
477+
const almostFullBalance =
478+
((delegationInfo.data?.balance ?? 0n) * 95n) / 100n
479+
480+
// If there's exactly one delegate AND the allocated amount is moast of the balance, present the option of native delegation
481+
if (
482+
2 == 2
483+
// allocatedDelegates.length === 1 &&
484+
// allocatedDelegates[0][1].newBalance > almostFullBalance
485+
) {
486+
return (
487+
<div className="flex w-[28rem] max-w-full flex-col gap-2">
488+
<div className="bg-ens-blue-surface flex flex-row items-center gap-2 rounded-lg p-4">
489+
<Typography asProp="p">
490+
Delegate a portion, swapping your $ENS for NFTs that
491+
represent each delegate. You can undelegate anytime to swap
492+
back, but new $ENS won’t be delegated automatically.
493+
</Typography>
494+
495+
<div>
496+
<RightArrowSVG className="text-ens-blue-dim" />
497+
</div>
498+
</div>
499+
<div className="bg-ens-blue-surface flex flex-row items-center gap-2 rounded-lg p-4">
500+
<Typography asProp="p">
501+
Delegate all your $ENS to one person, including any new $ENS
502+
you receive, for less gas.
503+
</Typography>
504+
505+
<div>
506+
<RightArrowSVG className="text-ens-blue-dim" />
507+
</div>
508+
</div>
509+
</div>
510+
)
511+
}
512+
513+
return (
514+
<div className="w-[28rem] max-w-full text-center">
515+
<Typography asProp="p">
516+
When you delegate your $ENS tokens they will be swapped for NFTs
517+
that represent each delegate. You can swap back to your tokens
518+
anytime by undelegating.
519+
</Typography>
520+
</div>
521+
)
522+
})()}
462523

463524
<Dialog.Footer
464525
leading={
@@ -472,7 +533,7 @@ export function Manage() {
472533
trailing={
473534
<Button
474535
colorStyle="bluePrimary"
475-
onClick={handleUpdate}
536+
onClick={handleMultiDelegate}
476537
loading={receipt.isLoading}
477538
disabled={toBeAllocated < 0n || changingDelegates.length === 0}
478539
>

apps/web/tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default {
88
blue: {
99
primary: '#3889FF',
1010
surface: '#EEF5FF',
11+
dim: '#056AFF',
1112
},
1213
grey: {
1314
primary: '#9B9BA6',

0 commit comments

Comments
 (0)