Skip to content

Commit

Permalink
Merge pull request #2376 from Emurgo/chore/token-and-nft-count-method
Browse files Browse the repository at this point in the history
Function for counting token and NFT types
  • Loading branch information
yushih committed Oct 8, 2021
2 parents 14aed31 + 73c720a commit 4802444
Show file tree
Hide file tree
Showing 37 changed files with 353 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ import type {
AccountStateFunc,
AddressUtxoFunc,
TokenInfoFunc,
MultiAssetMintMetadataFunc
} from './lib/state-fetch/types';
import type {
FilterFunc,
Expand Down Expand Up @@ -252,6 +253,7 @@ export type AdaGetTransactionsRequest = {|
checkAddressesInUse: FilterFunc,
getBestBlock: BestBlockFunc,
getTokenInfo: TokenInfoFunc,
getMultiAssetMetadata: MultiAssetMintMetadataFunc,
|};

// notices
Expand Down Expand Up @@ -658,6 +660,7 @@ export default class AdaApi {
request.getTransactionsHistoryForAddresses,
request.getBestBlock,
request.getTokenInfo,
request.getMultiAssetMetadata
);
}
const fetchedTxs = await getAllTransactions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
CatalystRoundInfoRequest, CatalystRoundInfoResponse,
BestBlockRequest, BestBlockResponse,
TokenInfoRequest, TokenInfoResponse,
MultiAssetMintMetadataRequest, MultiAssetMintMetadataResponse,
} from './types';
import type {
FilterUsedRequest, FilterUsedResponse,
Expand All @@ -30,4 +31,6 @@ export interface IFetcher {
getCatalystRoundInfo(body: CatalystRoundInfoRequest): Promise<CatalystRoundInfoResponse>;
getTokenInfo(body: TokenInfoRequest): Promise<TokenInfoResponse>;
checkAddressesInUse(body: FilterUsedRequest): Promise<FilterUsedResponse>;
getMultiAssetMintMetadata(body: MultiAssetMintMetadataRequest)
: Promise<MultiAssetMintMetadataResponse>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type {
TxBodiesFunc,
UtxoSumFunc,
RemoteTransaction,
MultiAssetMintMetadataRequest,
MultiAssetMintMetadataResponse
} from './types';
import type {
FilterFunc, FilterUsedRequest, FilterUsedResponse,
Expand Down Expand Up @@ -97,6 +99,11 @@ export class BatchedFetcher implements IFetcher {
this.baseFetcher.sendTx(body)
)

getMultiAssetMintMetadata: MultiAssetMintMetadataRequest
=> Promise<MultiAssetMintMetadataResponse> = (body) => (
this.baseFetcher.getMultiAssetMintMetadata(body)
)

getAccountState: AccountStateRequest => Promise<AccountStateResponse> = (body) => (
batchGetAccountState(this.baseFetcher.getAccountState)(body)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
SignedRequestInternal,
RemoteTransactionInput,
TokenInfoFunc,
MultiAssetMintMetadataFunc
} from './types';
import type {
FilterUsedRequest, FilterUsedResponse, FilterFunc,
Expand Down Expand Up @@ -672,3 +673,8 @@ export function genGetTokenInfo(
): TokenInfoFunc {
return async (_) => ({});
}

export function genGetMultiAssetMetadata(
): MultiAssetMintMetadataFunc {
return async (_) => ({});
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type {
UtxoSumResponse,
CatalystRoundInfoRequest,
CatalystRoundInfoResponse,
MultiAssetMintMetadataRequest,
MultiAssetMintMetadataResponse,
} from './types';
import type { FilterUsedRequest, FilterUsedResponse, } from '../../../common/lib/state-fetch/currencySpecificTypes';

Expand Down Expand Up @@ -427,4 +429,23 @@ export class RemoteFetcher implements IFetcher {
throw new GetCatalystRoundInfoApiError();
});
}

getMultiAssetMintMetadata: MultiAssetMintMetadataRequest
=> Promise<MultiAssetMintMetadataResponse> = async (body) => {
const { BackendService } = body.network.Backend;
if (BackendService == null) throw new Error(`${nameof(this.getMultiAssetMintMetadata)} missing backend url`);
return await axios(
`${BackendService}/api/multiAsset/metadata`,
{
method: 'post',
data: {
assets: body.assets
}
}
).then(response => response.data)
.catch((error) => {
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getMultiAssetMintMetadata)} error: ` + stringifyError(error));
return {};
});
}
}
26 changes: 25 additions & 1 deletion packages/yoroi-extension/app/api/ada/lib/state-fetch/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,28 @@ export type CatalystRoundInfoResponse = {|
|};

export type CatalystRoundInfoFunc = (body: CatalystRoundInfoRequest)
=> Promise<CatalystRoundInfoResponse>;
=> Promise<CatalystRoundInfoResponse>;

// Multi Asset Mint Metadata

export type MultiAssetMintMetadataFunc = (body: MultiAssetMintMetadataRequest)
=> Promise<MultiAssetMintMetadataResponse>;

export type MultiAssetMintMetadataRequest = {|
...BackendNetworkInfo,
assets: MultiAssetMintMetadataRequestAsset[]
|};

export type MultiAssetMintMetadataRequestAsset = {|
name: string,
policy: string
|}

export type MultiAssetMintMetadataResponse = {|
...{[key: string]: MultiAssetMintMetadataResponseAsset[]}
|}

export type MultiAssetMintMetadataResponseAsset = {|
key: string,
metadata: {[key: string]: any}
|}
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -597,6 +598,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -612,6 +614,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"boxId": "",
"description": null,
Expand All @@ -628,6 +631,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -643,6 +647,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -454,6 +455,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -469,6 +471,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"boxId": "",
"description": null,
Expand All @@ -485,6 +488,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -500,6 +504,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -458,6 +459,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -473,6 +475,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"boxId": "",
"description": null,
Expand All @@ -489,6 +492,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -504,6 +508,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -914,6 +915,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -929,6 +931,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"boxId": "",
"description": null,
Expand All @@ -945,6 +948,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -960,6 +964,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand Down Expand Up @@ -2062,6 +2067,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -2077,6 +2083,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -2092,6 +2099,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"boxId": "",
"description": null,
Expand All @@ -2108,6 +2116,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand All @@ -2123,6 +2132,7 @@ Array [
"Digest": 6.262633522161549e-167,
"Identifier": "",
"IsDefault": true,
"IsNFT": false,
"Metadata": Object {
"assetName": "",
"longName": null,
Expand Down

0 comments on commit 4802444

Please sign in to comment.