Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve FID for wallet addresses #6330

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/hooks/useFarcasterAccountForWallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { queryClient } from '@/react-query';
import useWallets from './useWallets';
import { useEffect, useMemo, useState } from 'react';
import { addysSummaryQueryKey, useAddysSummary } from '@/resources/summary/summary';
import { Address } from 'viem';
import useAccountSettings from './useAccountSettings';
import store from '@/redux/store';
import { isEmpty } from 'lodash';
import walletTypes from '@/helpers/walletTypes';
import { isLowerCaseMatch } from '@/utils';
import { AllRainbowWallets } from '@/model/wallet';

type SummaryData = ReturnType<typeof useAddysSummary>['data'];

const getWalletForAddress = (wallets: AllRainbowWallets, address: string) => {
return Object.values(wallets || {}).find(wallet => wallet.addresses.some(addr => isLowerCaseMatch(addr.address, address)));
};

export const useFarcasterWalletAddress = () => {
const [farcasterWalletAddress, setFarcasterWalletAddress] = useState<string | null>(null);
const { accountAddress } = useAccountSettings();
const { wallets } = useWallets();

const allAddresses = useMemo(
() => Object.values(wallets || {}).flatMap(wallet => (wallet.addresses || []).map(account => account.address as Address)),
[wallets]
);

useEffect(() => {
const summaryData = queryClient.getQueryData<SummaryData>(
addysSummaryQueryKey({
addresses: allAddresses,
currency: store.getState().settings.nativeCurrency,
})
);
if (isEmpty(summaryData?.data.addresses) || isEmpty(wallets)) {
setFarcasterWalletAddress(null);
return;
}

const selectedAddressFid = summaryData?.data.addresses[accountAddress as Address]?.meta?.farcaster?.fid;

if (selectedAddressFid && getWalletForAddress(wallets || {}, accountAddress)?.type !== walletTypes.readOnly) {
setFarcasterWalletAddress(accountAddress);
return;
}

const farcasterWalletAddress = Object.keys(summaryData?.data.addresses || {}).find(addr => {
const address = addr as Address;
const faracsterId = summaryData?.data.addresses[address]?.meta?.farcaster?.fid;
if (faracsterId && getWalletForAddress(wallets || {}, address)?.type !== walletTypes.readOnly) {
return faracsterId;
}
});

if (farcasterWalletAddress) {
setFarcasterWalletAddress(farcasterWalletAddress);
return;
}
setFarcasterWalletAddress(null);
}, [wallets, allAddresses, accountAddress]);

walmat marked this conversation as resolved.
Show resolved Hide resolved
console.log('farcasterWalletAddress', farcasterWalletAddress);
walmat marked this conversation as resolved.
Show resolved Hide resolved

return farcasterWalletAddress;
};
2 changes: 1 addition & 1 deletion src/hooks/useWalletBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAddysSummary } from '@/resources/summary/summary';
import { useQueries } from '@tanstack/react-query';
import { fetchPositions, positionsQueryKey } from '@/resources/defi/PositionsQuery';
import { RainbowPositions } from '@/resources/defi/types';
import { add, convertAmountToNativeDisplay, subtract } from '@/helpers/utilities';
import { add, convertAmountToNativeDisplay } from '@/helpers/utilities';
import { queryClient } from '@/react-query';

const QUERY_CONFIG = {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useWalletsHiddenBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NativeCurrencyKey } from '@/entities/nativeCurrencyTypes';
import { userAssetsStore } from '@/state/assets/userAssets';
import { queryClient } from '@/react-query';
import { userAssetsQueryKey, UserAssetsResult } from '@/resources/assets/UserAssetsQuery';
import { convertAmountAndPriceToNativeDisplay, add, isEqual, multiply } from '@/helpers/utilities';
import { add, isEqual, multiply } from '@/helpers/utilities';
import { isEqual as _isEqual } from 'lodash';

export type WalletBalanceResult = {
Expand Down
24 changes: 24 additions & 0 deletions src/resources/summary/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ interface AddysSummary {
data: {
addresses: {
[key: Address]: {
meta: {
farcaster?: {
object: string;
fid: number;
username: string;
display_name: string;
pfp_url: string;
custody_address: string;
profile: {
Bio: {
text: string;
};
};
follower_count: number;
following_count: number;
verifications: string[];
verified_addresses: {
eth_addresses: string[];
sol_addresses: string[];
};
verified_accounts: string[];
power_badge: boolean;
};
};
summary: {
native_balance_by_symbol: {
[key in 'ETH' | 'MATIC' | 'BNB' | 'AVAX']: {
Expand Down
Loading