Skip to content

Commit

Permalink
feat: add switch account functionality (#3308)
Browse files Browse the repository at this point in the history
* feat: create profile screen, add switch button

Signed-off-by: Prakhar Agarwal <[email protected]>

* feat: add profile item

Signed-off-by: Prakhar Agarwal <[email protected]>

* feat: loads data from persistant state, displays it, switch b/w accounts,  log out, and add new user

Signed-off-by: Prakhar Agarwal <[email protected]>

* feat: fetch usernames from backend

Signed-off-by: Prakhar Agarwal <[email protected]>

* feat: display profiles(fix #fb24fb) and enable switching

Signed-off-by: Prakhar Agarwal <[email protected]>

* fix: show switch option only when user is authenticated

Signed-off-by: Prakhar Agarwal <[email protected]>

* fix: call logout mutation

Signed-off-by: Prakhar Agarwal <[email protected]>

* fix: navigate to home screen on switching profile

Signed-off-by: Prakhar Agarwal <[email protected]>

* fix: switch icon color

Signed-off-by: Prakhar Agarwal <[email protected]>

* fix: disable back when loading data

Signed-off-by: Prakhar Agarwal <[email protected]>

* fix: go back 1 screen on profile switch

Signed-off-by: Prakhar Agarwal <[email protected]>

---------

Signed-off-by: Prakhar Agarwal <[email protected]>
  • Loading branch information
Prakhar-Agarwal-byte authored Jul 29, 2024
1 parent 8bd1533 commit e1d1683
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 34 deletions.
4 changes: 3 additions & 1 deletion app/assets/icons/switch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/graphql/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ const GaloyClient: React.FC<PropsWithChildren> = ({ children }) => {
if (token) {
authLink = setContext((request, { headers }) => ({
headers: {
...headers,
authorization: getAuthorizationHeader(token),
...headers,
},
}))
} else {
authLink = setContext((request, { headers }) => ({
headers: {
...headers,
authorization: "",
...headers,
},
}))
}
Expand Down
7 changes: 7 additions & 0 deletions app/graphql/generated.gql
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,13 @@ query transactionListForDefaultAccount($first: Int, $after: String, $last: Int,
}
}

query username {
me {
username
__typename
}
}

query walletOverviewScreen {
me {
id
Expand Down
44 changes: 44 additions & 0 deletions app/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,11 @@ export type OnChainUsdPaymentSendAsBtcDenominatedMutationVariables = Exact<{

export type OnChainUsdPaymentSendAsBtcDenominatedMutation = { readonly __typename: 'Mutation', readonly onChainUsdPaymentSendAsBtcDenominated: { readonly __typename: 'PaymentSendPayload', readonly status?: PaymentSendResult | null, readonly errors: ReadonlyArray<{ readonly __typename: 'GraphQLApplicationError', readonly message: string }> } };

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


export type UsernameQuery = { readonly __typename: 'Query', readonly me?: { readonly __typename: 'User', readonly username?: string | null } | null };

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


Expand Down Expand Up @@ -6748,6 +6753,45 @@ export function useOnChainUsdPaymentSendAsBtcDenominatedMutation(baseOptions?: A
export type OnChainUsdPaymentSendAsBtcDenominatedMutationHookResult = ReturnType<typeof useOnChainUsdPaymentSendAsBtcDenominatedMutation>;
export type OnChainUsdPaymentSendAsBtcDenominatedMutationResult = Apollo.MutationResult<OnChainUsdPaymentSendAsBtcDenominatedMutation>;
export type OnChainUsdPaymentSendAsBtcDenominatedMutationOptions = Apollo.BaseMutationOptions<OnChainUsdPaymentSendAsBtcDenominatedMutation, OnChainUsdPaymentSendAsBtcDenominatedMutationVariables>;
export const UsernameDocument = gql`
query username {
me {
username
}
}
`;

/**
* __useUsernameQuery__
*
* To run a query within a React component, call `useUsernameQuery` and pass it any options that fit your needs.
* When your component renders, `useUsernameQuery` 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 } = useUsernameQuery({
* variables: {
* },
* });
*/
export function useUsernameQuery(baseOptions?: Apollo.QueryHookOptions<UsernameQuery, UsernameQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<UsernameQuery, UsernameQueryVariables>(UsernameDocument, options);
}
export function useUsernameLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<UsernameQuery, UsernameQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<UsernameQuery, UsernameQueryVariables>(UsernameDocument, options);
}
export function useUsernameSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions<UsernameQuery, UsernameQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useSuspenseQuery<UsernameQuery, UsernameQueryVariables>(UsernameDocument, options);
}
export type UsernameQueryHookResult = ReturnType<typeof useUsernameQuery>;
export type UsernameLazyQueryHookResult = ReturnType<typeof useUsernameLazyQuery>;
export type UsernameSuspenseQueryHookResult = ReturnType<typeof useUsernameSuspenseQuery>;
export type UsernameQueryResult = Apollo.QueryResult<UsernameQuery, UsernameQueryVariables>;
export const AccountDeleteDocument = gql`
mutation accountDelete {
accountDelete {
Expand Down
1 change: 1 addition & 0 deletions app/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ const en: BaseTranslation = {
ProfileScreen: {
addNew : "Add new",
logout: "Logout",
error: "Unable to fetch profiles at this time",
},
TotpRegistrationInitiateScreen: {
title: "Two-factor authentication",
Expand Down
8 changes: 8 additions & 0 deletions app/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7590,6 +7590,10 @@ type RootTranslation = {
* L​o​g​o​u​t
*/
logout: string
/**
* U​n​a​b​l​e​ ​t​o​ ​f​e​t​c​h​ ​p​r​o​f​i​l​e​s​ ​a​t​ ​t​h​i​s​ ​t​i​m​e
*/
error: string
}
TotpRegistrationInitiateScreen: {
/**
Expand Down Expand Up @@ -16613,6 +16617,10 @@ export type TranslationFunctions = {
* Logout
*/
logout: () => LocalizedString
/**
* Unable to fetch profiles at this time
*/
error: () => LocalizedString
}
TotpRegistrationInitiateScreen: {
/**
Expand Down
3 changes: 2 additions & 1 deletion app/i18n/raw-i18n/source/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,8 @@
},
"ProfileScreen": {
"addNew": "Add new",
"logout": "Logout"
"logout": "Logout",
"error": "Unable to fetch profiles at this time"
},
"TotpRegistrationInitiateScreen": {
"title": "Two-factor authentication",
Expand Down
14 changes: 8 additions & 6 deletions app/screens/settings-screen/account/banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ export const AccountBanner = () => {
<Text type="p2">
{isUserLoggedIn ? usernameTitle : LL.SettingsScreen.logInOrCreateAccount()}
</Text>
<TouchableOpacity style={styles.switch} onPress={handleSwitchPress}>
<GaloyIcon name="switch" size={20} />
<Text type="p2" style={{ color: colors.primary }}>
{LL.AccountScreen.switch()}
</Text>
</TouchableOpacity>
{isUserLoggedIn && (
<TouchableOpacity style={styles.switch} onPress={handleSwitchPress}>
<GaloyIcon name="switch" size={20} color={colors.primary} />
<Text type="p2" style={{ color: colors.primary }}>
{LL.AccountScreen.switch()}
</Text>
</TouchableOpacity>
)}
</View>
</TouchableWithoutFeedback>
)
Expand Down
Loading

0 comments on commit e1d1683

Please sign in to comment.