// Copyright 2017-2019 @polkadot/react-components authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { I18nProps } from '../types';
import { QueueStatus, QueueTx, QueueTxStatus } from './types';
import React from 'react';
import styled from 'styled-components';
import { GenericCall } from '@polkadot/types';
import AddressMini from '../AddressMini';
import Button from '../Button';
import Icon from '../Icon';
import translate from '../translate';
import { classes } from '../util';
import { STATUS_COMPLETE } from './constants';
interface Props extends I18nProps {
stqueue?: QueueStatus[];
txqueue?: QueueTx[];
}
function iconName (status: string): any {
switch (status) {
case 'error':
return 'ban';
case 'event':
return 'assistive listening devices';
case 'received':
return 'telegram plane';
default:
return 'check';
}
}
function signerIconName (status: QueueTxStatus): any {
switch (status) {
case 'cancelled':
return 'ban';
case 'completed':
case 'finalized':
case 'sent':
return 'check';
case 'dropped':
case 'invalid':
case 'usurped':
return 'arrow down';
case 'error':
return 'warning sign';
case 'queued':
return 'random';
default:
return 'spinner';
}
}
function renderStatus ({ account, action, id, message, removeItem, status }: QueueStatus): React.ReactNode {
const addressRendered = account
?
: undefined;
return (
{action}
{addressRendered}
{message}
);
}
function renderItem ({ id, extrinsic, error, removeItem, rpc, status }: QueueTx): React.ReactNode {
let { method, section } = rpc;
if (extrinsic) {
const found = GenericCall.findFunction(extrinsic.callIndex);
if (found.section !== 'unknown') {
method = found.method;
section = found.section;
}
}
const icon = signerIconName(status);
return (