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

fix(portfolio): Wallet info not updated #3803

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/yoroi-extension/app/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export function wrapGovernance(governanceProps: StoresProps, children: Node): No
);
}
export function wrapPortfolio(portfolioProps: StoresProps, children: Node): Node {
const currentWalletInfo = createCurrrentWalletInfo(portfolioProps.stores);
const currentWalletInfo = React.useMemo(() => createCurrrentWalletInfo(portfolioProps.stores), [portfolioProps.stores]);

const openDialogWrapper = (dialog): void => {
portfolioProps.stores.uiDialogs.open({ dialog });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const HeaderPrice = ({ isLoading = false }) => {

return (
<Typography color="ds.text_gray_low" mr="12px">
{accountPair?.to.value} {accountPair?.to.name}
000 {accountPair?.to.value} {accountPair?.to.name}
</Typography>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PortfolioHeader = ({ walletBalance, setKeyword, isLoading, tooltipTitle }:
const [loading, setLoading] = React.useState(false);
const strings = useStrings();
const theme: any = useTheme();
const { unitOfAccount, changeUnitOfAccountPair, accountPair, primaryTokenInfo } = usePortfolio();
const { unitOfAccount, walletAdaBalance, changeUnitOfAccountPair, accountPair, primaryTokenInfo } = usePortfolio();
const { tokenActivity } = usePortfolioTokenActivity();
const localStorageApi = new LocalStorageApi();

Expand Down Expand Up @@ -94,8 +94,9 @@ const PortfolioHeader = ({ walletBalance, setKeyword, isLoading, tooltipTitle }:
};

if (portfolioStoragePairObj !== undefined) {
const fromValue = portfolioStoragePairObj.from.value !== walletBalance.ada ? walletBalance.ada : portfolioStoragePairObj.from.value;
changeUnitOfAccountPair({
from: { name: portfolioStoragePairObj.from.name, value: portfolioStoragePairObj.from.value },
from: { name: portfolioStoragePairObj.from.name, value: fromValue },
to: { name: portfolioStoragePairObj.to.name, value: !showADA ? walletBalance.ada : totalTokenPrice },
});
} else {
Expand All @@ -106,7 +107,7 @@ const PortfolioHeader = ({ walletBalance, setKeyword, isLoading, tooltipTitle }:
};

setFiatPair();
}, [totalTokenPrice, walletBalance, showADA]);
}, [totalTokenPrice, walletBalance, walletAdaBalance, showADA]);

if (!accountPair) {
return <LoadingSkeleton />;
Expand All @@ -120,7 +121,7 @@ const PortfolioHeader = ({ walletBalance, setKeyword, isLoading, tooltipTitle }:
<Skeleton width="146px" height="24px" />
) : (
<Typography variant="h2" fontWeight="500" color="ds.gray_cmax">
{String(accountPair?.from.value)}
0000 {String(accountPair?.from.value)}
</Typography>
)}
<CurrencyDisplay from={accountPair?.from?.name} handleCurrencyChange={handleCurrencyChange} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const PortfolioContextProvider = ({
currentWallet,
openDialogWrapper,
}: PortfolioProviderProps) => {
const { walletBalance, ftAssetList, selectedWallet, networkId, primaryTokenInfo, backendServiceZero, explorer } = currentWallet;
const { walletBalance, walletAdaBalance, ftAssetList, selectedWallet, networkId, primaryTokenInfo, backendServiceZero, explorer } = currentWallet;

if (selectedWallet === undefined) {
return <></>;
}
Expand Down Expand Up @@ -91,6 +92,7 @@ export const PortfolioContextProvider = ({
...actions,
settingFiatPairUnit,
walletBalance,
walletAdaBalance,
ftAssetList: ftAssetList || [],
networkId,
primaryTokenInfo,
Expand All @@ -99,7 +101,7 @@ export const PortfolioContextProvider = ({
backendServiceZero: backendServiceZero,
explorer,
}),
[state, actions, ftAssetList]
[state, currentWallet, actions, ftAssetList]
);

return <PortfolioContext.Provider value={context}>{children}</PortfolioContext.Provider>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type PortfolioState = {
};
accountPair: AccountPair | null;
walletBalance: WalletBalance | null;
walletAdaBalance: number;
networkId: number | null;
ftAssetList: any[];
showWelcomeBanner: boolean;
Expand All @@ -55,6 +56,7 @@ export const defaultPortfolioState: PortfolioState = {
},
accountPair: null,
walletBalance: null,
walletAdaBalance: 0,
networkId: null,
ftAssetList: [],
primaryTokenInfo: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ export const createCurrrentWalletInfo = (stores: any): CurrentWalletType | undef
try {
const walletCurrentPoolInfo = getStakePoolMeta(stores);

const selectedWallet /*: WalletState */ = wallets.selectedOrFail;
const walletAdaBalance /*: MultiToken */ = getWalletTotalAdaBalance(stores, selectedWallet);

const selectedWallet /*: WalletState */ = wallets.selected;

if (selectedWallet == null) {
throw new Error(`no selected Wallet. Should never happen`);
}


const walletAdaBalance /*: MultiToken */ = getWalletTotalAdaBalance(stores, selectedWallet);
const currentWalletId = selectedWallet.publicDeriverId;
const networkId = selectedWallet.networkId;

Expand Down
Loading