@polkadot/types#Tuple TypeScript Examples
The following examples show how to use
@polkadot/types#Tuple.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Justifications.tsx From crust-apps with Apache License 2.0 | 6 votes |
function formatTuple (tuple: Tuple): React.ReactNode {
const params = tuple.Types.map((type): { type: TypeDef } => ({
type: getTypeDef(type)
}));
const values = tuple.toArray().map((value): { isValid: boolean; value: Codec } => ({
isValid: true,
value
}));
return (
<Params
isDisabled
params={params}
values={values}
/>
);
}
Example #2
Source File: Justifications.tsx From crust-apps with Apache License 2.0 | 6 votes |
function JustificationList ({ value }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const headerRef = useRef([[t('justifications'), 'start']]);
const justifications = value.unwrapOr(null);
if (!justifications) {
return null;
}
return (
<Table
empty={t<string>('No justifications available')}
header={headerRef.current}
>
{justifications?.map((justification, index) => (
<tr key={`justification:${index}`}>
<td className='overflow'>
<Expander summary={justification[0].toString()}>
{formatTuple(justification as unknown as Tuple)}
</Expander>
</td>
</tr>
))}
</Table>
);
}
Example #3
Source File: Logs.tsx From crust-apps with Apache License 2.0 | 6 votes |
function formatTuple (tuple: Tuple): React.ReactNode {
const params = tuple.Types.map((type): { type: TypeDef } => ({
type: getTypeDef(type)
}));
const values = tuple.toArray().map((value): { isValid: boolean; value: Codec } => ({
isValid: true,
value
}));
return (
<Params
isDisabled
params={params}
values={values}
/>
);
}
Example #4
Source File: Logs.tsx From crust-apps with Apache License 2.0 | 6 votes |
function formatItem (item: DigestItem): React.ReactNode {
if (item.value instanceof Struct) {
return formatStruct(item.value);
} else if (item.value instanceof Tuple) {
return formatTuple(item.value);
} else if (item.value instanceof Vec) {
return formatVector(item.value);
} else if (item.value instanceof Raw) {
return formatU8a(item.value);
}
return <div>{item.value.toString().split(',').join(', ')}</div>;
}
Example #5
Source File: index.ts From subsocial-js with GNU General Public License v3.0 | 6 votes |
// ---------------------------------------------------------------------
// Is boolean
async isAccountFollower (myAddress: AnyAccountId, followedAddress: AnyAccountId): Promise<boolean> {
const followedAccountId = asAccountId(followedAddress)
const myAccountId = asAccountId(myAddress)
const queryParams = new Tuple(registry, [ GenericAccountId, GenericAccountId ], [ myAccountId, followedAccountId ]);
const isFollow = await this.queryPallet({ pallet: 'profileFollows', storage: 'accountFollowedByAccount' }, queryParams) as bool
return isFollow.valueOf()
}
Example #6
Source File: index.ts From subsocial-js with GNU General Public License v3.0 | 5 votes |
// TODO maybe pallet: 'posts' | 'spaces
private async isBooleanByAccount (params: StorageItem, accountId: AnyAccountId, subjectId: SubstrateId): Promise<boolean> {
const { storage, pallet } = params
const queryParams = new Tuple(registry, [ GenericAccountId, 'u64' ], [ asAccountId(accountId), subjectId ]);
const isBoolean = await this.queryPallet({ pallet, storage }, queryParams) as bool
return isBoolean.valueOf()
}
Example #7
Source File: index.ts From subsocial-js with GNU General Public License v3.0 | 5 votes |
private async getReactionIdsByAccount (accountId: AnyAccountId, structIds: AnyPostId[]): Promise<ReactionId[]> {
const queryParams = structIds.map(id => new Tuple(registry, [ GenericAccountId, 'u64' ], [ asAccountId(accountId), id ]));
return this.queryPalletMulti({ pallet: 'reactions', storage: 'postReactionIdByAccount' }, queryParams)
}