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

177 only show transfers for connected account #228

Merged
merged 9 commits into from
Aug 11, 2023
8 changes: 4 additions & 4 deletions src/helpers/spacewalk.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import bs58 from 'bs58';
import { H256 } from '@polkadot/types/interfaces';
import { ApiPromise } from '@polkadot/api';
import { U8aFixed } from '@polkadot/types-codec';
import { H256 } from '@polkadot/types/interfaces';
import { SpacewalkPrimitivesCurrencyId } from '@polkadot/types/lookup';
import bs58 from 'bs58';
import { DateTime } from 'luxon';
import { Asset, Keypair } from 'stellar-sdk';
import { convertRawHexKeyToPublicKey } from './stellar';
import { TenantName } from '../models/Tenant';
import { U8aFixed } from '@polkadot/types-codec';
import { convertRawHexKeyToPublicKey } from './stellar';

// Convert a hex string to an ASCII string
function hex_to_ascii(hexString: string, leading0x = true) {
Expand Down
14 changes: 7 additions & 7 deletions src/pages/bridge/TransferDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import WarningDialogIcon from '../../assets/dialog-status-warning';
import { CloseButton } from '../../components/CloseButton';
import { CopyableAddress } from '../../components/PublicKey';
import TransferCountdown from '../../components/TransferCountdown';
import { calculateDeadline, currencyToString, deriveShortenedRequestId } from '../../helpers/spacewalk';
import { calculateDeadline, convertCurrencyToStellarAsset, deriveShortenedRequestId } from '../../helpers/spacewalk';
import { convertRawHexKeyToPublicKey } from '../../helpers/stellar';
import { toTitle } from '../../helpers/string';
import { useSecurityPallet } from '../../hooks/spacewalk/security';
Expand Down Expand Up @@ -141,7 +141,7 @@ interface TransferDialogProps {

export function CompletedTransferDialog(props: TransferDialogProps) {
const { transfer, visible, onClose } = props;
const stellarAsset = currencyToString(transfer.original.asset);
const stellarAsset = convertCurrencyToStellarAsset(transfer.original.asset)?.getCode();
const content = (
<>
<div className="text-md">{`You have received ${transfer.amount} ${stellarAsset}`}</div>
Expand All @@ -168,7 +168,7 @@ export function CompletedTransferDialog(props: TransferDialogProps) {

export function CancelledTransferDialog(props: TransferDialogProps) {
const { transfer, visible, onClose } = props;
const stellarAsset = currencyToString(transfer.original.asset);
const stellarAsset = convertCurrencyToStellarAsset(transfer.original.asset)?.getCode();
const amountToSend = nativeToDecimal(transfer.original.amount.add(transfer.original.fee).toNumber()).toNumber();
const content = (
<>
Expand Down Expand Up @@ -204,7 +204,7 @@ export function ReimbursedTransferDialog(props: TransferDialogProps) {
const { transfer, visible, onClose } = props;
const tenant = useGlobalState().tenantName;

const stellarAsset = currencyToString(transfer.original.asset);
const stellarAsset = convertCurrencyToStellarAsset(transfer.original.asset)?.getCode();
const collateralAsset = transfer.original.vault.currencies.collateral;

const content = (
Expand All @@ -213,7 +213,7 @@ export function ReimbursedTransferDialog(props: TransferDialogProps) {
{'Your redeem request failed but you decided to burn ' +
stellarAsset +
' in return for ' +
currencyToString(collateralAsset, tenant)}
convertCurrencyToStellarAsset(collateralAsset)?.getCode()}
</div>
<h1 className="text-xl">
{transfer.amount} {stellarAsset}
Expand All @@ -237,7 +237,7 @@ export function ReimbursedTransferDialog(props: TransferDialogProps) {

export function PendingTransferDialog(props: TransferDialogProps) {
const { transfer, visible, onClose } = props;
const stellarAsset = currencyToString(transfer.original.asset);
const stellarAsset = convertCurrencyToStellarAsset(transfer.original.asset)?.getCode();
const destinationStellarAddress = convertRawHexKeyToPublicKey(transfer.original.stellarAddress.toHex()).publicKey();
const amountToSend = nativeToDecimal(transfer.original.amount.add(transfer.original.fee).toNumber());
const { getActiveBlockNumber } = useSecurityPallet();
Expand Down Expand Up @@ -310,7 +310,7 @@ export function PendingTransferDialog(props: TransferDialogProps) {

export function FailedTransferDialog(props: TransferDialogProps) {
const { transfer, visible, onClose } = props;
const stellarAsset = currencyToString(transfer.original.asset);
const stellarAsset = convertCurrencyToStellarAsset(transfer.original.asset)?.getCode();
const amountToSend = nativeToDecimal(transfer.original.amount.add(transfer.original.fee).toNumber()).toNumber();
const compensation = 0.05;
const content = (
Expand Down
27 changes: 22 additions & 5 deletions src/pages/bridge/Transfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Transfers(): JSX.Element {
const { getIssueRequests } = useIssuePallet();
const { getRedeemRequests } = useRedeemPallet();
const { subscribeActiveBlockNumber } = useSecurityPallet();
const { tenantName } = useGlobalState();
const { tenantName, walletAccount } = useGlobalState();
const [currentTransfer, setCurrentTransfer] = useState<TTransfer | undefined>();
const [activeBlockNumber, setActiveBlockNumber] = useState<number>(0);
const [data, setData] = useState<TTransfer[] | undefined>(undefined);
Expand All @@ -53,41 +53,58 @@ function Transfers(): JSX.Element {
const entries: TTransfer[] = [];

issueEntries.forEach((e) => {
if (!walletAccount || !e.request.requester.eq(walletAccount?.address)) {
return;
}

const deadline = calculateDeadline(
activeBlockNumber as number,
e.request.opentime.toNumber(),
e.request.period.toNumber(),
);

const timedOut = deadline < DateTime.now();

const pending = e.request.status.type === 'Pending';
entries.push({
updated: estimateRequestCreationTime(activeBlockNumber as number, e.request.opentime.toNumber()),
amount: nativeToDecimal(e.request.amount.toString()).toString(),
asset: convertCurrencyToStellarAsset(e.request.asset)?.code,
transactionId: e.id.toString(),
type: TransferType.issue,
status: timedOut ? 'Cancelled' : e.request.status.type,
status: timedOut && pending ? 'Cancelled' : e.request.status.type,
original: e.request,
});
});

redeemEntries.forEach((e) => {
if (!walletAccount || !e.request.redeemer.eq(walletAccount?.address)) {
return;
}

const deadline = calculateDeadline(
activeBlockNumber as number,
e.request.opentime.toNumber(),
e.request.period.toNumber(),
);

const timedOut = deadline < DateTime.now();
const pending = e.request.status.type === 'Pending';

entries.push({
updated: estimateRequestCreationTime(activeBlockNumber as number, e.request.opentime.toNumber()),
amount: nativeToDecimal(e.request.amount.toString()).toString(),
asset: convertCurrencyToStellarAsset(e.request.asset)?.code,
transactionId: e.id.toString(),
type: TransferType.redeem,
status: e.request.status.type,
status: timedOut && pending ? 'Failed' : e.request.status.type,
original: e.request,
});
});

return entries;
};
fetchAllEntries().then((res) => setData(res));
}, [activeBlockNumber, getIssueRequests, getRedeemRequests]);
}, [activeBlockNumber, walletAccount, getIssueRequests, getRedeemRequests]);

const columns = useMemo(() => {
const detailsColumn = detailsColumnCreator(setCurrentTransfer);
Expand Down
Loading