Skip to content

Commit

Permalink
Merge pull request #55 from Monobladegg/main
Browse files Browse the repository at this point in the history
Fixed bug about loading Because of firebase
  • Loading branch information
grandmotivator authored Nov 9, 2024
2 parents 6217aa7 + c9f13d3 commit 780d3cc
Show file tree
Hide file tree
Showing 10 changed files with 2,136 additions and 808 deletions.
2 changes: 1 addition & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=

# GitHub (optional)
Expand Down
2,825 changes: 2,082 additions & 743 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ async function getAllTransactions(
net: "public" | "testnet"
): Promise<TransactionData[]> {
if (!firestore) {
throw new Error("Firestore not initialized");
console.warn("Firestore not initialized");
return [];
}

let collectionName: string;
Expand Down
10 changes: 1 addition & 9 deletions src/shared/lib/processKeys/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,13 @@ const processKeys = (
let processedValue: string = value;

// Convert regular expression strings to RegExp objects with boundaries and case-insensitive flag
const regexPatterns: { [type: string]: RegExp[] } = Object.entries(
Object.entries(
dataKeys
).reduce((acc, [type, patterns]) => {
acc[type] = patterns.map((pattern) => new RegExp(`^${pattern}$`, "i"));
return acc;
}, {} as { [type: string]: RegExp[] });

const isValidKey = Object.values(regexPatterns).some((patterns) =>
patterns.some((pattern) => pattern.test(key))
);

if (!isValidKey) {
console.log("")
}

// Decode base64 value
const decodedValue = decodeBase64(value);

Expand Down
25 changes: 18 additions & 7 deletions src/shared/store/slices/firebase/firebaseSettingsSlice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,27 @@ export const firebaseSettingsSlice: StateCreator<
}
}

const newFirebaseApp = initializeApp(config, name);
set({ firebaseApp: newFirebaseApp });

const newFirestore = getFirestore(newFirebaseApp);
set({ firestore: newFirestore });
if (
config.apiKey &&
config.appId &&
config.messagingSenderId &&
config.storageBucket &&
config.projectId &&
config.authDomain
) {
const newFirebaseApp = initializeApp(config, name);
set({ firebaseApp: newFirebaseApp });

if (newFirebaseApp) {
const newFirestore = getFirestore(newFirebaseApp);
set({ firestore: newFirestore });
return newFirebaseApp;
}
}

return newFirebaseApp;
};

const setFirestore = (newFirestore: Firestore) => {
const setFirestore = (newFirestore: Firestore | undefined) => {
set({ firestore: newFirestore });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ export interface FirebaseAppState {
}

export interface FirebaseAppActions {
initializeFirebase: (config: FirebaseOptions) => FirebaseApp;
setFirestore: (firestore: Firestore) => void;
initializeFirebase: (
config: FirebaseOptions,
appName?: string
) => FirebaseApp | undefined;
setFirestore: (firestore: Firestore | undefined) => void;
}

interface IFirebaseSettingsSlice extends FirebaseAppState, FirebaseAppActions {}
Expand Down
4 changes: 1 addition & 3 deletions src/views/Layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const PageLayout: FC<Props> = ({ children }) => {
setLastFetchedHash(latestHash);

} catch (error) {
console.error("Error fetching commit hash:", error);
console.warn("Error fetching commit hash:", error);
}
};

Expand Down Expand Up @@ -164,7 +164,6 @@ const PageLayout: FC<Props> = ({ children }) => {
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
});
} else {
initializeFirebase({
Expand All @@ -176,7 +175,6 @@ const PageLayout: FC<Props> = ({ children }) => {
"Firebase-messagingSenderId"
)!,
appId: window.localStorage.getItem("Firebase-appId")!,
measurementId: window.localStorage.getItem("Firebase-measurementId")!,
});
}
}, []);
Expand Down
60 changes: 25 additions & 35 deletions src/views/account/AccountInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const AccountInfo: FC<Props> = ({ ID }) => {
setInformation,
information,
firestore,
firebaseApp,
} = useStore(useShallow((state) => state));
const [secondInformation, setSecondInformation] = useState<Information>();
const [seqNumsIsStales, setSeqNumsIsStales] = useState<ISeqNumIsStale[]>([]);
Expand All @@ -83,13 +84,20 @@ const AccountInfo: FC<Props> = ({ ID }) => {

useEffect(() => {
if (
information?.signers &&
information.signers.length > 0 &&
(decodedTransactions === null || decodedTransactions.length > 0)
(information?.signers &&
information.signers.length > 0 &&
(decodedTransactions === null ||
(decodedTransactions.length > 0 && firestore && firebaseApp))) ||
(Array.isArray(decodedTransactions) &&
decodedTransactions.length === 0 &&
!firestore &&
!firebaseApp)
) {
setIsLoading(false);
} else {
setIsLoading(true);
}
}, [information, decodedTransactions]);
}, [information, decodedTransactions, firestore, firebaseApp]);

useEffect(() => {
const newCollapsesBlocks = { ...collapsesBlocks };
Expand Down Expand Up @@ -170,10 +178,6 @@ const AccountInfo: FC<Props> = ({ ID }) => {
}
}, [accounts, information.signers]);

useEffect(() => {
console.log(information.signers);
}, [information.signers]);

useEffect(() => {
setIsVisibleTx(false);
}, [ID, accounts]);
Expand Down Expand Up @@ -267,31 +271,23 @@ const AccountInfo: FC<Props> = ({ ID }) => {

useEffect(() => {
const fetchTransactions = async () => {
try {
const transactions = await getAllTransactions(firestore, net);
setTransactionsFromFirebase(transactions);
const transactions = await getAllTransactions(firestore, net);
setTransactionsFromFirebase(transactions);

const decodedList: DecodedTransactions = [];
const decodedList: DecodedTransactions = [];

transactions.forEach(({ xdr }, index) => {
try {
const transaction = TransactionBuilder.fromXDR(
xdr,
network
) as Transaction;
transactions.forEach(({ xdr }, index) => {
const transaction = TransactionBuilder.fromXDR(
xdr,
network
) as Transaction;

if (transaction.source === ID) {
decodedList.push({ index, transaction });
}
} catch (error) {
console.error("Ошибка при декодировании транзакции:", error);
}
});
if (transaction.source === ID) {
decodedList.push({ index, transaction });
}
});

setDecodedTransactions(decodedList.length > 0 ? decodedList : null);
} catch (error) {
console.error("Ошибка при получении транзакций:", error);
}
setDecodedTransactions(decodedList.length > 0 ? decodedList : null);
};

if (net && ID) {
Expand Down Expand Up @@ -333,12 +329,6 @@ const AccountInfo: FC<Props> = ({ ID }) => {
return [];
}, [information?.signers]);

useEffect(() => {
console.log("collapsesBlocks.transactions", collapsesBlocks.transactions);
console.log("isVisibleTx", isVisibleTx);
console.log("decodedTransactions", decodedTransactions);
}, [decodedTransactions, isVisibleTx, collapsesBlocks.transactions]);

return (
<MainLayout>
<div className="container">
Expand Down
2 changes: 1 addition & 1 deletion src/views/account/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Account: FC = () => {
const [isValidId, setIsValidId] = useState<boolean | null>(null);
const params = useSearchParams();
const id: string | undefined | null = params?.get("id");

useEffect(() => {
if (id) setIsValidId(StellarSdk.StrKey.isValidEd25519PublicKey(id));
}, [id]);
Expand Down
6 changes: 0 additions & 6 deletions src/widgets/Layout/Modals/FirebaseSettingsModal/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const FirebaseSettingsModal: FC = () => {
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "",
});

const changeFormValue = (key: keyof FirebaseOptions, value: string) => {
Expand All @@ -58,8 +57,6 @@ const FirebaseSettingsModal: FC = () => {
messagingSenderId:
window.localStorage.getItem("Firebase-messagingSenderId") ?? "",
appId: window.localStorage.getItem("Firebase-appId") ?? "",
measurementId:
window.localStorage.getItem("Firebase-measurementId") ?? "",
});
setCurrentFirebase(
(window.localStorage.getItem(
Expand All @@ -79,8 +76,6 @@ const FirebaseSettingsModal: FC = () => {
messagingSenderId:
window.localStorage.getItem("Firebase-messagingSenderId") ?? "",
appId: window.localStorage.getItem("Firebase-appId") ?? "",
measurementId:
window.localStorage.getItem("Firebase-measurementId") ?? "",
});
} else {
initializeFirebase({
Expand All @@ -90,7 +85,6 @@ const FirebaseSettingsModal: FC = () => {
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
});

console.log(firebaseApp);
Expand Down

0 comments on commit 780d3cc

Please sign in to comment.