2023-08-29 13:57:02 +00:00
|
|
|
import { LedgerExportForm } from '@vegaprotocol/ledger';
|
|
|
|
import { Loader, Splash } from '@vegaprotocol/ui-toolkit';
|
2024-03-01 14:25:56 +00:00
|
|
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
2023-08-29 13:57:02 +00:00
|
|
|
import { useEnvironment } from '@vegaprotocol/environment';
|
|
|
|
import type { PartyAssetFieldsFragment } from '@vegaprotocol/assets';
|
|
|
|
import { usePartyAssetsQuery } from '@vegaprotocol/assets';
|
2023-11-16 03:10:39 +00:00
|
|
|
import { useT } from '../../lib/use-t';
|
2023-06-27 00:10:22 +00:00
|
|
|
|
|
|
|
export const LedgerContainer = () => {
|
2023-11-16 03:10:39 +00:00
|
|
|
const t = useT();
|
2023-08-29 13:57:02 +00:00
|
|
|
const VEGA_URL = useEnvironment((store) => store.VEGA_URL);
|
2023-06-27 00:10:22 +00:00
|
|
|
const { pubKey } = useVegaWallet();
|
2023-08-29 13:57:02 +00:00
|
|
|
const { data, loading } = usePartyAssetsQuery({
|
|
|
|
variables: { partyId: pubKey || '' },
|
|
|
|
skip: !pubKey,
|
2023-06-27 00:10:22 +00:00
|
|
|
});
|
|
|
|
|
2023-08-29 13:57:02 +00:00
|
|
|
const assets = (data?.party?.accountsConnection?.edges ?? [])
|
2023-11-29 12:28:31 +00:00
|
|
|
.map((item) => item?.node?.asset)
|
|
|
|
.filter((asset): asset is PartyAssetFieldsFragment => !!asset?.id)
|
|
|
|
.reduce(
|
|
|
|
(aggr, item) => Object.assign(aggr, { [item.id]: item.symbol }),
|
|
|
|
{} as Record<string, string>
|
|
|
|
);
|
2023-08-29 13:57:02 +00:00
|
|
|
|
2023-06-27 00:10:22 +00:00
|
|
|
if (!pubKey) {
|
|
|
|
return (
|
|
|
|
<Splash>
|
|
|
|
<p>{t('Please connect Vega wallet')}</p>
|
|
|
|
</Splash>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-29 13:57:02 +00:00
|
|
|
if (!VEGA_URL) {
|
|
|
|
return (
|
|
|
|
<Splash>
|
|
|
|
<p>{t('Environment not configured')}</p>
|
|
|
|
</Splash>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return (
|
|
|
|
<div className="relative flex items-center justify-center w-full h-full">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object.keys(assets).length) {
|
|
|
|
return (
|
|
|
|
<Splash>
|
|
|
|
<p>{t('No ledger entries to export')}</p>
|
|
|
|
</Splash>
|
|
|
|
);
|
|
|
|
}
|
2023-06-27 00:10:22 +00:00
|
|
|
|
2023-08-29 13:57:02 +00:00
|
|
|
return (
|
|
|
|
<LedgerExportForm partyId={pubKey} vegaUrl={VEGA_URL} assets={assets} />
|
|
|
|
);
|
|
|
|
};
|