@@ -2,6 +2,7 @@ import { useMemo } from "react";
2
2
3
3
import { Check } from "lucide-react" ;
4
4
import Link from "next/link" ;
5
+ import { isError } from "remeda" ;
5
6
6
7
import { BLOCKCHAIN_EXPLORER_TX_ENDPOINT_URL } from "@/common/_config" ;
7
8
import { type PotId , indexer } from "@/common/api/indexer" ;
@@ -25,7 +26,7 @@ import {
25
26
} from "@/common/ui/components" ;
26
27
import TwitterSvg from "@/common/ui/svg/twitter" ;
27
28
import { useWalletUserSession } from "@/common/wallet" ;
28
- import { AccountProfileLink } from "@/entities/_shared/account" ;
29
+ import { AccountProfileLink , useAccountSocialProfile } from "@/entities/_shared/account" ;
29
30
import { TokenTotalValue , useToken } from "@/entities/_shared/token" ;
30
31
import { rootPathnames } from "@/pathnames" ;
31
32
@@ -45,7 +46,7 @@ export const DonationSuccess = ({ form, transactionHash, closeModal }: DonationS
45
46
const viewer = useWalletUserSession ( ) ;
46
47
const { finalOutcome } = useDonationState ( ) ;
47
48
const isResultLoading = finalOutcome === undefined ;
48
- const [ potId ] = form . watch ( [ "potAccountId" ] ) ;
49
+ const [ potId , recipientAccountIdFormValue ] = form . watch ( [ "potAccountId" , "recipientAccountId "] ) ;
49
50
50
51
const { data : pot } = indexer . usePot ( {
51
52
enabled : potId !== undefined ,
@@ -54,24 +55,32 @@ export const DonationSuccess = ({ form, transactionHash, closeModal }: DonationS
54
55
55
56
const recipientAccountId = useMemo (
56
57
( ) =>
57
- "recipient_id" in ( finalOutcome ?? { } )
58
+ ( "recipient_id" in ( finalOutcome ?? { } )
58
59
? ( finalOutcome as DirectDonation ) . recipient_id
59
- : ( ( finalOutcome as PotDonation ) . project_id ?? undefined ) ,
60
+ : ( finalOutcome as PotDonation ) . project_id ) ?? recipientAccountIdFormValue ,
60
61
61
- [ finalOutcome ] ,
62
+ [ finalOutcome , recipientAccountIdFormValue ] ,
62
63
) ;
63
64
64
- const { data : recipient , error : recipientDataError } = indexer . useAccount ( {
65
+ const {
66
+ isLoading : isRecipientSocialProfileLoading ,
67
+ profile : recipientSocialProfile ,
68
+ error : recipientProfileLoadingError ,
69
+ } = useAccountSocialProfile ( {
65
70
enabled : recipientAccountId !== undefined ,
66
71
accountId : recipientAccountId ?? "noop" ,
67
72
} ) ;
68
73
69
- const tokenId =
70
- "ft_id" in ( finalOutcome ?? { } ) ? ( finalOutcome as DirectDonation ) . ft_id : NATIVE_TOKEN_ID ;
74
+ const tokenId = useMemo (
75
+ ( ) =>
76
+ "ft_id" in ( finalOutcome ?? { } ) ? ( finalOutcome as DirectDonation ) . ft_id : NATIVE_TOKEN_ID ,
71
77
72
- const { data : token } = useToken ( { tokenId } ) ;
78
+ [ finalOutcome ] ,
79
+ ) ;
73
80
74
- const isLoading = isResultLoading || recipient === undefined || token === undefined ;
81
+ const { isLoading : isTokenLoading , data : token } = useToken ( { tokenId } ) ;
82
+
83
+ const isLoading = isResultLoading || isRecipientSocialProfileLoading || isTokenLoading ;
75
84
76
85
const totalAmountFloat = indivisibleUnitsToFloat (
77
86
finalOutcome ?. total_amount ?? "0" ,
@@ -97,41 +106,56 @@ export const DonationSuccess = ({ form, transactionHash, closeModal }: DonationS
97
106
} ) ;
98
107
99
108
const twitterIntent = useMemo ( ( ) => {
100
- if ( ! recipient ?. near_social_profile_data ) return ;
101
- const twitterIntentBase = "https://twitter.com/intent/tweet?text=" ;
102
-
103
- const profile = recipient . near_social_profile_data ;
104
-
105
- const text = encodeURIComponent ( `🎉 Just supported ${
106
- profile . linktree ?. twitter
107
- ? `${ profile . name } (@${ profile . linktree . twitter } )`
108
- : `${ profile . name } (${ recipient . id } )`
109
- } through @${ PLATFORM_TWITTER_ACCOUNT_ID } !
110
-
111
- 💝 Making an impact by funding public goods that shape our future.
112
-
113
- 🤝 Join me in supporting amazing projects:\n` ) ;
114
-
115
- const url = encodeURIComponent (
116
- `${ APP_DEFAULT_PUBLIC_URL } ${ rootPathnames . PROFILE } /${ recipient . id } /donations` ,
117
- ) ;
118
-
119
- const relation = encodeURIComponent ( APP_DEFAULT_PUBLIC_URL ) ;
120
-
121
- return (
122
- twitterIntentBase +
123
- text +
124
- `&url=${ url } ` +
125
- `&related=${ relation } ` +
126
- `&hashtags=${ DEFAULT_SHARE_HASHTAGS . join ( "," ) } `
127
- ) ;
128
- } , [ recipient ?. id , recipient ?. near_social_profile_data ] ) ;
129
-
130
- return recipientDataError !== undefined ? (
109
+ if ( recipientAccountId !== undefined ) {
110
+ const twitterIntentBase = "https://twitter.com/intent/tweet?text=" ;
111
+
112
+ const text = encodeURIComponent (
113
+ `🎉 Just supported ${
114
+ recipientSocialProfile ?. linktree ?. twitter
115
+ ? `${ recipientSocialProfile ?. name ?? recipientAccountId } (@${
116
+ recipientSocialProfile . linktree . twitter
117
+ } )`
118
+ : `${
119
+ recipientSocialProfile ?. name !== undefined &&
120
+ recipientSocialProfile ?. name ?. length > 1
121
+ ? `${ recipientSocialProfile . name } (${ recipientAccountId } )`
122
+ : recipientAccountId
123
+ } `
124
+ } through @${ PLATFORM_TWITTER_ACCOUNT_ID } !\n\n` +
125
+ "💝 Making an impact by funding public goods that shape our future." +
126
+ `\n\n🤝 Join me in supporting amazing projects:\n` ,
127
+ ) ;
128
+
129
+ // viewer.isSignedIn
130
+ // ? `?referrerAccountId=${viewer.accountId}`
131
+ // : "",
132
+
133
+ const url = encodeURIComponent (
134
+ `${ APP_DEFAULT_PUBLIC_URL } ${ rootPathnames . PROFILE } /${ recipientAccountId } /donations` ,
135
+ ) ;
136
+
137
+ const relation = encodeURIComponent ( APP_DEFAULT_PUBLIC_URL ) ;
138
+
139
+ return (
140
+ twitterIntentBase +
141
+ text +
142
+ `&url=${ url } ` +
143
+ `&related=${ relation } ` +
144
+ `&hashtags=${ DEFAULT_SHARE_HASHTAGS . join ( "," ) } `
145
+ ) ;
146
+ } else return undefined ;
147
+ } , [ recipientAccountId , recipientSocialProfile ] ) ;
148
+
149
+ return recipientProfileLoadingError !== undefined ||
150
+ ( ! isResultLoading && recipientAccountId === undefined ) ? (
131
151
< ModalErrorBody
132
152
heading = "Donation"
133
153
title = "Unable to load recipient data!"
134
- message = { recipientDataError ?. message }
154
+ message = {
155
+ isError ( recipientProfileLoadingError )
156
+ ? recipientProfileLoadingError . message
157
+ : recipientProfileLoadingError
158
+ }
135
159
/>
136
160
) : (
137
161
< DialogDescription className = "items-center gap-8 p-10" >
@@ -181,14 +205,17 @@ export const DonationSuccess = ({ form, transactionHash, closeModal }: DonationS
181
205
< TokenTotalValue amountBigString = { finalOutcome . total_amount } { ...{ tokenId } } />
182
206
) }
183
207
184
- { isLoading ? (
208
+ { isLoading || recipientAccountId === undefined ? (
185
209
< Skeleton className = "w-49 h-5" />
186
210
) : (
187
211
< p className = "m-0 flex flex-col" >
188
212
< div className = "flex gap-1" >
189
213
< span className = "prose" > { "has been donated to" } </ span >
190
214
191
- < AccountProfileLink accountId = { recipient . id } classNames = { { name : "font-600" } } />
215
+ < AccountProfileLink
216
+ accountId = { recipientAccountId }
217
+ classNames = { { name : "font-600" } }
218
+ />
192
219
</ div >
193
220
194
221
{ pot ?. name && (
@@ -197,11 +224,11 @@ export const DonationSuccess = ({ form, transactionHash, closeModal }: DonationS
197
224
</ p >
198
225
) }
199
226
200
- { isLoading ? (
227
+ { isLoading || recipientAccountId === undefined ? (
201
228
< Skeleton className = "w-23.5 h-5" />
202
229
) : (
203
230
< Link
204
- href = { `${ rootPathnames . PROFILE } /${ recipient . id } /funding-raised` }
231
+ href = { `${ rootPathnames . PROFILE } /${ recipientAccountId } /funding-raised` }
205
232
onClick = { closeModal }
206
233
className = "font-500 text-red-600"
207
234
>
0 commit comments