Skip to content

Commit

Permalink
feat(SPV-802): adjust pike config to new variables (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 authored Jun 5, 2024
1 parent 77fa155 commit fcacba7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/api/types/serverConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type ExperimentalConfig = {
pike_enabled: boolean;
pike_contacts_enabled: boolean;
pike_payment_enabled: boolean;
};

export type ServerConfig = {
Expand Down
6 changes: 3 additions & 3 deletions src/components/TransferForm/TransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ContactStatus } from '@/api';
import { StatusBadge } from '../ContactsList/ContactsTable.tsx/StatusBadge';
import styled from '@emotion/styled';
import { PaymailAutocomplete } from '../Input/PaymailAutocomplete';
import { usePikeEnabled } from '@/hooks/useFeatureFlags';
import { usePikeContactsEnabled } from '@/hooks/useFeatureFlags';

type TransferFormProps = {
showContactsButton?: boolean;
Expand All @@ -32,7 +32,7 @@ export const TransferForm: FC<TransferFormProps> = ({ showContactsButton }) => {
const [loading, setLoading] = useState<boolean>(false);
const [transactionData, setTransactionData] = useState<TransactionData | null>(null);
const [errors, setErrors] = useState<string>('');
const pikeEnabled = usePikeEnabled();
const pikeContactsEnabled = usePikeContactsEnabled();

const sendButtonDisabled = !paymail || !amount;
const cancelButtonDisabled = !paymail && !amount;
Expand Down Expand Up @@ -130,7 +130,7 @@ export const TransferForm: FC<TransferFormProps> = ({ showContactsButton }) => {
showContactsButton={showContactsButton}
/>
<StyledStatusWrapper>
{pikeEnabled && paymailStatus != null && (
{pikeContactsEnabled && paymailStatus != null && (
<>
This is <StatusBadge status={paymailStatus} style={{ display: 'inline-block' }} />{' '}
{paymailStatus !== 'unknown' ? 'contact' : 'paymail'}
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export const useExperimentalFeatures = () => {
return useServerConfig().experimental_features;
};

export const usePikeEnabled = () => {
return useExperimentalFeatures().pike_enabled;
export const usePikePaymentEnabled = () => {
return useExperimentalFeatures().pike_payment_enabled;
};


export const usePikeContactsEnabled = () => {
return useExperimentalFeatures().pike_contacts_enabled;
};
8 changes: 4 additions & 4 deletions src/providers/contacts/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { searchContacts } from '@/api/requests/contact';
import { Contact } from '@/api/types/contact';
import { PaginationParams } from '@/api/types';
import { usePikeEnabled } from '@/hooks/useFeatureFlags';
import { usePikeContactsEnabled } from '@/hooks/useFeatureFlags';
import { FC, PropsWithChildren, createContext, useCallback, useEffect, useMemo, useState } from 'react';
import { useAuthorization } from '../authorization';

Expand All @@ -18,11 +18,11 @@ export const ContactsProvider: FC<PropsWithChildren> = ({ children }) => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [contacts, setContacts] = useState<Contact[] | null>(null);
const enabled = usePikeEnabled();
const pikeContactsEnabled = usePikeContactsEnabled()
const { authorization } = useAuthorization();

const load = useCallback(async () => {
if (!enabled || !authorization) {
if (!pikeContactsEnabled || !authorization) {
return;
}
setLoading(true);
Expand All @@ -41,7 +41,7 @@ export const ContactsProvider: FC<PropsWithChildren> = ({ children }) => {
} finally {
setLoading(false);
}
}, [authorization, enabled]);
}, [authorization, pikeContactsEnabled]);

const refresh = useCallback(() => {
load();
Expand Down
6 changes: 3 additions & 3 deletions src/views/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { AccountSummary } from '@/components/AccountSummary';
import { TransferForm } from '@/components/TransferForm';
import { TransactionHistory } from '@/components/TransactionHistory';
import { useWebsocket } from '@/hooks';
import { usePikeEnabled } from '@/hooks/useFeatureFlags';
import { usePikeContactsEnabled } from '@/hooks/useFeatureFlags';

export const Dashboard = () => {
const lgMatch = useMediaMatch('lg');
useWebsocket();

const pikeEnabled = usePikeEnabled();
const pikeContactsEnabled = usePikeContactsEnabled();

return (
<>
Expand All @@ -20,7 +20,7 @@ export const Dashboard = () => {
</Column>
<Column percentageWidth={lgMatch ? 30 : 100}>
<AccountSummary />
<TransferForm showContactsButton={pikeEnabled} />
<TransferForm showContactsButton={pikeContactsEnabled} />
</Column>
</Row>
</>
Expand Down

0 comments on commit fcacba7

Please sign in to comment.