@@ -13,6 +13,7 @@ import { KeyValueT, NETWORK_TICKERS_FROM_ID, ResponseMessage, SOCKET_MESSAGES }
1313import config from 'config'
1414import io from 'socket.io-client'
1515import PaybuttonTrigger from 'components/Paybutton/PaybuttonTrigger'
16+ import { UserProfile } from '@prisma/client'
1617
1718export const getServerSideProps : GetServerSideProps = async ( context ) => {
1819 supertokensNode . init ( SuperTokensConfig . backendConfig ( ) )
@@ -39,17 +40,33 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
3940
4041interface PaybuttonProps {
4142 paybuttonId : string
43+ userId : string
4244}
4345
4446export default function Button ( props : PaybuttonProps ) : React . ReactElement {
45- const [ paybutton , setPaybutton ] = useState ( undefined as PaybuttonWithAddresses | undefined )
47+ const [ paybutton , setPaybutton ] = useState < PaybuttonWithAddresses | undefined > ( undefined )
4648 const [ isSyncing , setIsSyncing ] = useState < KeyValueT < boolean > > ( { } )
4749 const [ tableRefreshCount , setTableRefreshCount ] = useState < number > ( 0 )
4850 const [ paybuttonNetworks , setPaybuttonNetworks ] = useState < number [ ] > ( [ ] )
49-
5051 const [ selectedCurrency , setSelectedCurrency ] = useState < string > ( '' )
52+ const [ userProfile , setUserProfile ] = useState < UserProfile | null > ( null )
53+
5154 const router = useRouter ( )
5255
56+ useEffect ( ( ) => {
57+ void ( async ( ) => {
58+ try {
59+ const res = await fetch ( '/api/user/' , {
60+ method : 'GET'
61+ } )
62+ const profile = await res . json ( )
63+ setUserProfile ( profile )
64+ } catch ( error ) {
65+ console . error ( 'Error fetching user profile:' , error )
66+ }
67+ } ) ( )
68+ } , [ ] )
69+
5370 const updateIsSyncing = ( addressStringList : string [ ] ) : void => {
5471 const newIsSyncing = { ...isSyncing }
5572 addressStringList . forEach ( ( addressString ) => {
@@ -108,10 +125,11 @@ export default function Button (props: PaybuttonProps): React.ReactElement {
108125
109126 const downloadCSV = async ( paybutton : { id : string , name : string } , currency : string ) : Promise < void > => {
110127 try {
111- let url = `/api/paybutton/download/transactions/${ paybutton . id } `
128+ const preferredCurrencyId = userProfile ?. preferredCurrencyId ?? ''
129+ let url = `/api/paybutton/download/transactions/${ paybutton . id } ?currency=${ preferredCurrencyId } `
112130 const isCurrencyEmptyOrUndefined = ( value : string ) : boolean => ( value === '' || value === undefined )
113131 if ( ! isCurrencyEmptyOrUndefined ( currency ) ) {
114- url += `? network=${ currency } `
132+ url += `& network=${ currency } `
115133 }
116134 const response = await fetch ( url )
117135
0 commit comments