Skip to content

Commit c589948

Browse files
committed
improvements
1 parent a840887 commit c589948

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

packages/grant-explorer/src/features/round/DonateToGitcoin.tsx

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,24 @@ export function DonateToGitcoin({ divider = "none" }: DonateToGitcoinProps) {
153153
<Listbox value={selectedToken} onChange={setSelectedToken}>
154154
<div className="relative">
155155
<Listbox.Button className="relative w-40 cursor-default rounded-lg border border-gray-200 bg-white py-2 pl-3 pr-8 text-left text-sm shadow-sm hover:border-gray-300">
156-
{selectedToken
157-
? selectedChain?.tokens.find(
158-
(t) => t.address === selectedToken
159-
)?.code
160-
: "Select token"}
156+
{selectedToken ? (
157+
<div className="flex justify-between items-center">
158+
<span>
159+
{
160+
selectedChain?.tokens.find(
161+
(t) =>
162+
t.address.toLowerCase() ===
163+
selectedToken.toLowerCase()
164+
)?.code
165+
}
166+
</span>
167+
<span className="text-xs text-gray-500 ml-2">
168+
{selectedTokenBalance.toFixed(3)}
169+
</span>
170+
</div>
171+
) : (
172+
"Select token"
173+
)}
161174
</Listbox.Button>
162175
<Transition
163176
as={Fragment}
@@ -172,6 +185,37 @@ export function DonateToGitcoin({ divider = "none" }: DonateToGitcoinProps) {
172185
<div className="max-h-[40vh] overflow-y-auto">
173186
{selectedChain?.tokens
174187
.filter((token) => token.address !== zeroAddress)
188+
.sort((a, b) => {
189+
// NATIVE token always first
190+
if (
191+
a.address.toLowerCase() === NATIVE.toLowerCase()
192+
)
193+
return -1;
194+
if (
195+
b.address.toLowerCase() === NATIVE.toLowerCase()
196+
)
197+
return 1;
198+
199+
// Get balances
200+
const balanceA =
201+
tokenBalances.find(
202+
(b) =>
203+
b.token.toLowerCase() ===
204+
a.address.toLowerCase()
205+
)?.balance || 0;
206+
const balanceB =
207+
tokenBalances.find(
208+
(b) =>
209+
b.token.toLowerCase() ===
210+
b.token.toLowerCase()
211+
)?.balance || 0;
212+
213+
// Sort by balance (highest to lowest)
214+
if (balanceA === 0 && balanceB === 0) return 0;
215+
if (balanceA === 0) return 1;
216+
if (balanceB === 0) return -1;
217+
return balanceB - balanceA;
218+
})
175219
.map((token) => {
176220
const balance =
177221
tokenBalances.find(
@@ -221,12 +265,6 @@ export function DonateToGitcoin({ divider = "none" }: DonateToGitcoinProps) {
221265
</div>
222266
)}
223267
</div>
224-
225-
{selectedToken && (
226-
<span className="text-sm text-gray-500 whitespace-nowrap">
227-
Balance: {selectedTokenBalance.toFixed(3)}
228-
</span>
229-
)}
230268
</div>
231269
)}
232270

0 commit comments

Comments
 (0)