Skip to content

Commit

Permalink
fix: DarthCoin rant
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Dec 8, 2023
1 parent 0d49abe commit 63bbe9b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
33 changes: 28 additions & 5 deletions app/components/amount-input-screen/amount-input-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react"
import { WalletCurrency } from "@app/graphql/generated"
import { WalletCurrency, useSwapDefaultUnitOfAccountQuery } from "@app/graphql/generated"
import { CurrencyInfo, useDisplayCurrency } from "@app/hooks/use-display-currency"
import { useI18nContext } from "@app/i18n/i18n-react"
import { ConvertMoneyAmount } from "@app/screens/send-bitcoin-screen/payment-details"
Expand All @@ -19,6 +19,8 @@ import {
NumberPadReducerActionType,
NumberPadReducerState,
} from "./number-pad-reducer"
import { setSwapDefaultUnitOfAccount } from "@app/graphql/client-only-query"
import { useApolloClient } from "@apollo/client"

export type AmountInputScreenProps = {
goBack: () => void
Expand Down Expand Up @@ -198,11 +200,32 @@ export const AmountInputScreen: React.FC<AmountInputScreenProps> = ({
[currencyInfo],
)

const onToggleCurrency =
secondaryNewAmount &&
(() => {
const client = useApolloClient()
const swapDefaultUnitOfAccount =
useSwapDefaultUnitOfAccountQuery().data?.swapDefaultUnitOfAccount
const [needSwapCurrencyInit, setNeedSwapCurrencyInit] = React.useState(
swapDefaultUnitOfAccount,
)

const onToggleCurrency = React.useCallback(() => {
if (secondaryNewAmount) {
setSwapDefaultUnitOfAccount(client, !swapDefaultUnitOfAccount)
setNumberPadAmount(secondaryNewAmount)
})
}
}, [secondaryNewAmount, setNumberPadAmount, client, swapDefaultUnitOfAccount])

useEffect(() => {
if (needSwapCurrencyInit && secondaryNewAmount) {
setNeedSwapCurrencyInit(false)
setNumberPadAmount(secondaryNewAmount)
}
}, [
swapDefaultUnitOfAccount,
onToggleCurrency,
secondaryNewAmount,
needSwapCurrencyInit,
setNumberPadAmount,
])

useEffect(() => {
if (initialAmount) {
Expand Down
3 changes: 3 additions & 0 deletions app/graphql/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export const createCache = () =>
introducingCirclesModalShown: {
read: (value) => value ?? false,
},
swapDefaultUnitOfAccount: {
read: (value) => value ?? false,
},
innerCircleValue: {
read: (value) => value ?? -1,
},
Expand Down
23 changes: 23 additions & 0 deletions app/graphql/client-only-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
InnerCircleValueQuery,
IntroducingCirclesModalShownDocument,
IntroducingCirclesModalShownQuery,
SwapDefaultUnitOfAccountDocument,
SwapDefaultUnitOfAccountQuery,
} from "./generated"

export default gql`
Expand Down Expand Up @@ -49,6 +51,10 @@ export default gql`
query innerCircleValue {
innerCircleValue @client
}
query swapDefaultUnitOfAccount {
swapDefaultUnitOfAccount @client
}
`

export const saveHideBalance = (
Expand Down Expand Up @@ -173,3 +179,20 @@ export const setInnerCircleCachedValue = (
console.warn("unable to update InnerCircleValueDocument")
}
}

export const setSwapDefaultUnitOfAccount = (
client: ApolloClient<unknown>,
swapDefaultUnitOfAccount: boolean,
) => {
try {
client.writeQuery<SwapDefaultUnitOfAccountQuery>({
query: SwapDefaultUnitOfAccountDocument,
data: {
__typename: "Query",
swapDefaultUnitOfAccount,
},
})
} catch {
console.warn("unable to update SwapDefaultUnitOfAccountDocument")
}
}
4 changes: 4 additions & 0 deletions app/graphql/generated.gql
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,10 @@ query supportedCountries {
}
}

query swapDefaultUnitOfAccount {
swapDefaultUnitOfAccount @client
}

query totpRegistrationScreen {
me {
username
Expand Down
39 changes: 39 additions & 0 deletions app/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,7 @@ export type Query = {
readonly quizQuestions?: Maybe<ReadonlyArray<Maybe<QuizQuestion>>>;
/** Returns 1 Sat and 1 Usd Cent price for the given currency */
readonly realtimePrice: RealtimePrice;
readonly swapDefaultUnitOfAccount: Scalars['Boolean']['output'];
/** @deprecated will be migrated to AccountDefaultWalletId */
readonly userDefaultWalletId: Scalars['WalletId']['output'];
readonly usernameAvailable?: Maybe<Scalars['Boolean']['output']>;
Expand Down Expand Up @@ -2239,6 +2240,11 @@ export type InnerCircleValueQueryVariables = Exact<{ [key: string]: never; }>;

export type InnerCircleValueQuery = { readonly __typename: 'Query', readonly innerCircleValue: number };

export type SwapDefaultUnitOfAccountQueryVariables = Exact<{ [key: string]: never; }>;


export type SwapDefaultUnitOfAccountQuery = { readonly __typename: 'Query', readonly swapDefaultUnitOfAccount: boolean };

export type TransactionFragment = { readonly __typename: 'Transaction', readonly id: string, readonly status: TxStatus, readonly direction: TxDirection, readonly memo?: string | null, readonly createdAt: number, readonly settlementAmount: number, readonly settlementFee: number, readonly settlementDisplayFee: string, readonly settlementCurrency: WalletCurrency, readonly settlementDisplayAmount: string, readonly settlementDisplayCurrency: string, readonly settlementPrice: { readonly __typename: 'PriceOfOneSettlementMinorUnitInDisplayMinorUnit', readonly base: number, readonly offset: number, readonly currencyUnit: string, readonly formattedAmount: string }, readonly initiationVia: { readonly __typename: 'InitiationViaIntraLedger', readonly counterPartyWalletId?: string | null, readonly counterPartyUsername?: string | null } | { readonly __typename: 'InitiationViaLn', readonly paymentHash: string, readonly paymentRequest: string } | { readonly __typename: 'InitiationViaOnChain', readonly address: string }, readonly settlementVia: { readonly __typename: 'SettlementViaIntraLedger', readonly counterPartyWalletId?: string | null, readonly counterPartyUsername?: string | null } | { readonly __typename: 'SettlementViaLn', readonly preImage?: string | null } | { readonly __typename: 'SettlementViaOnChain', readonly transactionHash?: string | null, readonly arrivalInMempoolEstimatedAt?: number | null } };

export type TransactionListFragment = { readonly __typename: 'TransactionConnection', readonly pageInfo: { readonly __typename: 'PageInfo', readonly hasNextPage: boolean, readonly hasPreviousPage: boolean, readonly startCursor?: string | null, readonly endCursor?: string | null }, readonly edges?: ReadonlyArray<{ readonly __typename: 'TransactionEdge', readonly cursor: string, readonly node: { readonly __typename: 'Transaction', readonly id: string, readonly status: TxStatus, readonly direction: TxDirection, readonly memo?: string | null, readonly createdAt: number, readonly settlementAmount: number, readonly settlementFee: number, readonly settlementDisplayFee: string, readonly settlementCurrency: WalletCurrency, readonly settlementDisplayAmount: string, readonly settlementDisplayCurrency: string, readonly settlementPrice: { readonly __typename: 'PriceOfOneSettlementMinorUnitInDisplayMinorUnit', readonly base: number, readonly offset: number, readonly currencyUnit: string, readonly formattedAmount: string }, readonly initiationVia: { readonly __typename: 'InitiationViaIntraLedger', readonly counterPartyWalletId?: string | null, readonly counterPartyUsername?: string | null } | { readonly __typename: 'InitiationViaLn', readonly paymentHash: string, readonly paymentRequest: string } | { readonly __typename: 'InitiationViaOnChain', readonly address: string }, readonly settlementVia: { readonly __typename: 'SettlementViaIntraLedger', readonly counterPartyWalletId?: string | null, readonly counterPartyUsername?: string | null } | { readonly __typename: 'SettlementViaLn', readonly preImage?: string | null } | { readonly __typename: 'SettlementViaOnChain', readonly transactionHash?: string | null, readonly arrivalInMempoolEstimatedAt?: number | null } } }> | null };
Expand Down Expand Up @@ -3498,6 +3504,38 @@ export function useInnerCircleValueLazyQuery(baseOptions?: Apollo.LazyQueryHookO
export type InnerCircleValueQueryHookResult = ReturnType<typeof useInnerCircleValueQuery>;
export type InnerCircleValueLazyQueryHookResult = ReturnType<typeof useInnerCircleValueLazyQuery>;
export type InnerCircleValueQueryResult = Apollo.QueryResult<InnerCircleValueQuery, InnerCircleValueQueryVariables>;
export const SwapDefaultUnitOfAccountDocument = gql`
query swapDefaultUnitOfAccount {
swapDefaultUnitOfAccount @client
}
`;

/**
* __useSwapDefaultUnitOfAccountQuery__
*
* To run a query within a React component, call `useSwapDefaultUnitOfAccountQuery` and pass it any options that fit your needs.
* When your component renders, `useSwapDefaultUnitOfAccountQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useSwapDefaultUnitOfAccountQuery({
* variables: {
* },
* });
*/
export function useSwapDefaultUnitOfAccountQuery(baseOptions?: Apollo.QueryHookOptions<SwapDefaultUnitOfAccountQuery, SwapDefaultUnitOfAccountQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<SwapDefaultUnitOfAccountQuery, SwapDefaultUnitOfAccountQueryVariables>(SwapDefaultUnitOfAccountDocument, options);
}
export function useSwapDefaultUnitOfAccountLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<SwapDefaultUnitOfAccountQuery, SwapDefaultUnitOfAccountQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<SwapDefaultUnitOfAccountQuery, SwapDefaultUnitOfAccountQueryVariables>(SwapDefaultUnitOfAccountDocument, options);
}
export type SwapDefaultUnitOfAccountQueryHookResult = ReturnType<typeof useSwapDefaultUnitOfAccountQuery>;
export type SwapDefaultUnitOfAccountLazyQueryHookResult = ReturnType<typeof useSwapDefaultUnitOfAccountLazyQuery>;
export type SwapDefaultUnitOfAccountQueryResult = Apollo.QueryResult<SwapDefaultUnitOfAccountQuery, SwapDefaultUnitOfAccountQueryVariables>;
export const NetworkDocument = gql`
query network {
globals {
Expand Down Expand Up @@ -8143,6 +8181,7 @@ export type QueryResolvers<ContextType = any, ParentType extends ResolversParent
price?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
quizQuestions?: Resolver<Maybe<ReadonlyArray<Maybe<ResolversTypes['QuizQuestion']>>>, ParentType, ContextType>;
realtimePrice?: Resolver<ResolversTypes['RealtimePrice'], ParentType, ContextType, RequireFields<QueryRealtimePriceArgs, 'currency'>>;
swapDefaultUnitOfAccount?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
userDefaultWalletId?: Resolver<ResolversTypes['WalletId'], ParentType, ContextType, RequireFields<QueryUserDefaultWalletIdArgs, 'username'>>;
usernameAvailable?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType, RequireFields<QueryUsernameAvailableArgs, 'username'>>;
welcomeLeaderboard?: Resolver<ResolversTypes['Leaderboard'], ParentType, ContextType, RequireFields<QueryWelcomeLeaderboardArgs, 'input'>>;
Expand Down
1 change: 1 addition & 0 deletions app/graphql/local-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extend type Query {
hasPromptedSetDefaultAccount: Boolean!
introducingCirclesModalShown: Boolean!
innerCircleValue: Int!
swapDefaultUnitOfAccount: Boolean!
}

extend type Account {
Expand Down

0 comments on commit 63bbe9b

Please sign in to comment.