-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Tip Claim frontend integration (#202)
* Tip claim frontend integration * Change fee calculation * Use env for app * Set estimation gas amount to 1 & tips icon * Fix estimated fee * Install wallet dialog * Transaction hash text * Fix estimation * Disable STRK & JBY tokens * Toast container padding * Picker web style * Change fee multiplication
- Loading branch information
Showing
39 changed files
with
619 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
EXPO_PUBLIC_NETWORK="SN_SEPOLIA" # SN_SEPOLIA, SN_MAIN | ||
EXPO_PUBLIC_PROVIDER_URL="https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/your_api_key" | ||
|
||
EXPO_PUBLIC_BACKEND_URL="http://localhost:3000/api" | ||
|
||
EXPO_PUBLIC_WC_ID="your_wallet_connect_project_id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {constants} from 'starknet'; | ||
|
||
export const NETWORK_NAME = process.env.EXPO_PUBLIC_NETWORK as constants.NetworkName; | ||
export const PROVIDER_URL = process.env.EXPO_PUBLIC_PROVIDER_URL; | ||
|
||
export const BACKEND_URL = process.env.EXPO_PUBLIC_BACKEND_URL; | ||
|
||
export const WALLET_CONNECT_ID = process.env.EXPO_PUBLIC_WC_ID; | ||
|
||
if (!Object.keys(constants.NetworkName).includes(NETWORK_NAME)) { | ||
throw new Error(`Invalid network name: ${NETWORK_NAME}`); | ||
} | ||
if (!PROVIDER_URL) throw new Error('Missing PROVIDER_URL env variable'); | ||
if (!BACKEND_URL) throw new Error('Missing BACKEND_URL env variable'); | ||
if (!WALLET_CONNECT_ID) throw new Error('Missing WALLET_CONNECT_ID env variable'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {useClaim} from './useClaim'; | ||
export {useEstimateClaim} from './useEstimateClaim'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
QueryClient, | ||
useMutation, | ||
UseMutationOptions, | ||
UseMutationResult, | ||
} from '@tanstack/react-query'; | ||
import {AxiosError} from 'axios'; | ||
import {useEffect} from 'react'; | ||
|
||
import {useToast} from '../modals'; | ||
|
||
export const useApiMutation = < | ||
TFnData = unknown, | ||
TData = TFnData, | ||
TVariables = void, | ||
TContext = unknown, | ||
>( | ||
options: UseMutationOptions<TFnData, AxiosError, TVariables, TContext>, | ||
showErrorToast = true, | ||
queryClient: QueryClient | undefined = undefined, | ||
): UseMutationResult<TData, AxiosError, TVariables, TContext> => { | ||
const mutation = useMutation(options, queryClient); | ||
|
||
const {showToast} = useToast(); | ||
|
||
useEffect(() => { | ||
if (showErrorToast && mutation.error) { | ||
const {response} = mutation.error; | ||
if (!response || typeof response.data !== 'object' || !('code' in response.data)) { | ||
showToast({ | ||
type: 'error', | ||
title: 'Request failed with no response, please try again later.', | ||
}); | ||
return; | ||
} | ||
|
||
showToast({ | ||
type: 'error', | ||
title: `Request failed with error code: ${response.data.code}`, | ||
}); | ||
} | ||
|
||
return () => { | ||
// | ||
}; | ||
}, [showErrorToast, mutation.error, showToast]); | ||
|
||
return mutation as any; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {NostrEvent} from '@nostr-dev-kit/ndk'; | ||
|
||
import {ApiInstance} from '../../services/api'; | ||
import {useApiMutation} from './useApiMutation'; | ||
|
||
export const useClaim = () => { | ||
return useApiMutation({ | ||
mutationKey: ['claim'], | ||
mutationFn: (event: NostrEvent) => { | ||
return ApiInstance.post('/deposit/claim', {event}); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {NostrEvent} from '@nostr-dev-kit/ndk'; | ||
|
||
import {ApiInstance} from '../../services/api'; | ||
import {useApiMutation} from './useApiMutation'; | ||
|
||
export const useEstimateClaim = () => { | ||
return useApiMutation({ | ||
mutationKey: ['estimateClaim'], | ||
mutationFn: (event: NostrEvent) => { | ||
return ApiInstance.post('/deposit/estimate-claim', {event}); | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.