@polkadot/types/interfaces#AccountIndex TypeScript Examples
The following examples show how to use
@polkadot/types/interfaces#AccountIndex.
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: AccountName.tsx From crust-apps with Apache License 2.0 | 6 votes |
function defaultOrAddr (defaultName = '', _address: AccountId | AccountIndex | Address | string | Uint8Array, _accountIndex?: AccountIndex | null): [React.ReactNode, boolean, boolean, boolean] {
const known = KNOWN.find(([known]) => known.eq(_address));
if (known) {
return [known[1], false, false, true];
}
const accountId = _address.toString();
if (!accountId) {
return [defaultName, false, false, false];
}
const [isAddressExtracted,, extracted] = getAddressName(accountId, null, defaultName);
const accountIndex = (_accountIndex || '').toString() || indexCache.get(accountId);
if (isAddressExtracted && accountIndex) {
indexCache.set(accountId, accountIndex);
return [accountIndex, false, true, false];
}
return [extracted, !isAddressExtracted, isAddressExtracted, false];
}
Example #2
Source File: AccountName.tsx From crust-apps with Apache License 2.0 | 6 votes |
function extractName (address: string, accountIndex?: AccountIndex, defaultName?: string): React.ReactNode {
const displayCached = displayCache.get(address);
if (displayCached) {
return displayCached;
}
const [displayName, isLocal, isAddress, isSpecial] = defaultOrAddr(defaultName, address, accountIndex);
return (
<div className='via-identity'>
{isSpecial && (
<Badge
color='green'
icon='archway'
isSmall
/>
)}
<span className={`name${(isLocal || isSpecial) ? ' isLocal' : (isAddress ? ' isAddress' : '')}`}>{displayName}</span>
</div>
);
}
Example #3
Source File: AccountName.tsx From subscan-multisig-react with Apache License 2.0 | 6 votes |
function defaultOrAddr(
defaultName = '',
_address: AccountId | AccountIndex | Address | string | Uint8Array,
_accountIndex?: AccountIndex | null
): [React.ReactNode, boolean, boolean, boolean] {
// eslint-disable-next-line @typescript-eslint/no-shadow
const known = KNOWN.find(([known]) => known.eq(_address));
if (known) {
return [known[1], false, false, true];
}
const accountId = _address.toString();
if (!accountId) {
return [defaultName, false, false, false];
}
const [isAddressExtracted, , extracted] = getAddressName(accountId, null, defaultName);
const accountIndex = (_accountIndex || '').toString() || indexCache.get(accountId);
if (isAddressExtracted && accountIndex) {
indexCache.set(accountId, accountIndex);
return [accountIndex, false, true, false];
}
return [extracted, !isAddressExtracted, isAddressExtracted, false];
}
Example #4
Source File: AccountName.tsx From subscan-multisig-react with Apache License 2.0 | 6 votes |
function extractName(address: string, accountIndex?: AccountIndex, defaultName?: string): React.ReactNode {
const displayCached = displayCache.get(address);
if (displayCached) {
return displayCached;
}
const [displayName, isLocal, isAddress, isSpecial] = defaultOrAddr(defaultName, address, accountIndex);
return (
<div className="via-identity">
{isSpecial && <Badge color="green" icon="archway" isSmall />}
<span className={`name${isLocal || isSpecial ? ' isLocal' : isAddress ? ' isAddress' : ''}`}>{displayName}</span>
</div>
);
}
Example #5
Source File: index.tsx From crust-apps with Apache License 2.0 | 5 votes |
function isCodec (value?: AccountId | AccountIndex | Address | string | Uint8Array | null): value is AccountId | AccountIndex | Address {
return !!(value && (value as AccountId).toHuman);
}
Example #6
Source File: toShortAddress.ts From crust-apps with Apache License 2.0 | 5 votes |
export default function toShortAddress (_address?: AccountId | AccountIndex | Address | string | null | Uint8Array): string {
const address = (_address || '').toString();
return (address.length > 13)
? `${address.slice(0, 6)}…${address.slice(-6)}`
: address;
}
Example #7
Source File: toShortAddress.ts From subscan-multisig-react with Apache License 2.0 | 5 votes |
export default function toShortAddress(
_address?: AccountId | AccountIndex | Address | string | null | Uint8Array
): string {
const address = (_address || '').toString();
return address.length > 13 ? `${address.slice(0, 6)}…${address.slice(-6)}` : address;
}
Example #8
Source File: equilibrium.ts From crust-apps with Apache License 2.0 | 4 votes |
definitions: OverrideBundleDefinition = {
types: [
{
// on all versions
minmax: [0, undefined],
types: {
Address: 'AccountId',
Balance: 'u64',
BalanceOf: 'Balance',
BalancesAggregate: {
total_issuance: 'Balance',
total_debt: 'Balance'
},
BlockNumber: 'u64',
ChainId: 'u8',
Currency: {
_enum: ['Unknown', 'Usd', 'EQ', 'Eth', 'Btc', 'Eos', 'Dot']
},
DataPoint: {
price: 'u64',
account_id: 'AccountId',
block_number: 'BlockNumber',
timestamp: 'u64'
},
DepositNonce: 'u64',
FixedI64: 'i64',
Keys: 'SessionKeys3',
LookupSource: 'AccountId',
OperationRequest: {
account: 'AccountId',
authority_index: 'AuthIndex',
validators_len: 'u32',
block_num: 'BlockNumber'
},
PricePayload: 'Data',
PricePeriod: {
_enum: ['Min', 'TenMin', 'Hour', 'FourHour', 'Day']
},
PricePoint: {
block_number: 'BlockNumber',
timestamp: 'u64',
price: 'u64',
data_points: 'Vec<DataPoint>'
},
ProposalStatus: {
_enum: [
'Initiated',
'Approved',
'Rejected'
]
},
ProposalVotes: {
votes_for: 'Vec<AccountId>',
votes_against: 'Vec<AccountId>',
status: 'ProposalStatus',
expiry: 'BlockNumber'
},
ReinitRequest: {
account: 'AccountId',
authority_index: 'AuthIndex',
validators_len: 'u32',
block_num: 'BlockNumber'
},
ResourceId: '[u8; 32]',
SignedBalance: {
_enum: {
Positive: 'Balance',
Negative: 'Balance'
}
},
SubAccType: {
_enum: ['Bailsman', 'Borrower', 'Lender']
},
TotalAggregates: {
collateral: 'Balance',
debt: 'Balance'
},
TransferReason: {
_enum: [
'Common',
'InterestFee',
'MarginCall',
'BailsmenRedistribution',
'TreasuryEqBuyout',
'TreasuryBuyEq',
'Subaccount'
]
},
UserGroup: {
_enum: ['Unknown', 'Balances', 'Bailsmen', 'Borrowers', 'Lenders']
},
VestingInfo: {
locked: 'Balance',
perBlock: 'Balance',
startingBlock: 'BlockNumber'
}
}
}
],
derives: {
// TODO derive.democracy.locks
// TODO derice.staking.account
balances: {
account: (
// Compatibility with calc tx fee
instanceId: string,
api: ApiInterfaceRx
): EQDeriveBalancesAccountQuery =>
memo(
instanceId,
(address: AccountId | AccountIndex | Address | string) =>
api.derive.accounts.accountId(address).pipe(
switchMap(
(accountId): Observable<[AccountId, [Index]]> =>
accountId
? combineLatest([
of(accountId),
api
.queryMulti([
[api.query.system.account, accountId]
])
.pipe(
map((raw): [Index] => {
if (raw.length < 1) {
throw new Error('Data expected');
}
const data = raw as [AccountInfo];
return [data[0].nonce];
})
)
])
: of([
api.registry.createType('AccountId'),
[api.registry.createType('Index')]
])
),
map(([, [accountNonce]]) => ({ accountNonce }))
)
),
all: (
// Compatibility for account balance in explorer
instanceId: string,
api: ApiInterfaceRx
): EQDeriveBalancesAllQuery =>
memo(
instanceId,
(address: AccountIndex | AccountId | Address | string) =>
api.derive.accounts.accountId(address).pipe(
switchMap(
(accountId): Observable<[AccountId, Result]> =>
accountId
? combineLatest([
of(accountId),
api
.queryMulti([
[api.query.balances.account, [accountId, 'EQ']],
[api.query.eqVesting.vested, accountId],
[api.query.eqVesting.vesting, accountId],
[api.query.system.account, accountId]
])
.pipe(
map(
(raw): Result => {
if (raw.length < 4) {
throw new Error('4 members expected');
}
const res = raw as RawResult;
const freeBalance = res[0].asPositive;
let reservedBalance = api.registry.createType(
'Balance'
);
let vestingLocked = api.registry.createType(
'Balance'
);
if (res[1].isSome && res[2].isSome) {
const vested = res[1].unwrap();
const info = res[2].unwrap();
vestingLocked = info.locked;
reservedBalance = api.registry.createType(
'Balance',
vestingLocked.sub(vested)
);
}
return [
freeBalance,
reservedBalance,
vestingLocked,
res[3].nonce
];
}
)
)
])
: of([
api.registry.createType('AccountId'),
[
api.registry.createType('Balance'),
api.registry.createType('Balance'),
api.registry.createType('Balance'),
api.registry.createType('Index')
]
])
),
map(
([
accountId,
[freeBalance, reservedBalance, vestingLocked, accountNonce]
]): EQDeriveBalancesAll => ({
accountId,
accountNonce,
additional: [],
freeBalance,
lockedBalance: vestingLocked,
lockedBreakdown: [],
reservedBalance,
vestingLocked
})
)
)
)
}
}
}