Skip to content

Commit

Permalink
Merge pull request #641 from telosnetwork/epic-allowances
Browse files Browse the repository at this point in the history
Epic - allowances
  • Loading branch information
donnyquixotic authored Dec 26, 2023
2 parents 04eb91c + 1c43925 commit fed530f
Show file tree
Hide file tree
Showing 50 changed files with 3,204 additions and 296 deletions.
46 changes: 41 additions & 5 deletions src/antelope/chains/EVMChainSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ import {
IndexerAccountNftsFilter,
IndexerAccountNftsResponse,
GenericIndexerNft,
IndexerNftContract,
IndexerContract,
NftRawData,
IndexerCollectionNftsResponse,
Erc721Nft,
getErc721Owner,
Erc1155Nft,
AntelopeError,
IndexerAllowanceFilter,
IndexerAllowanceResponseErc20,
IndexerAllowanceResponseErc721,
IndexerAllowanceResponseErc1155,
getErc1155OwnersFromIndexer,
} from 'src/antelope/types';
import EvmContract from 'src/antelope/stores/utils/contracts/EvmContract';
Expand Down Expand Up @@ -378,12 +382,12 @@ export default abstract class EVMChainSettings implements ChainSettings {
imageCache: nftResponse.imageCache,
tokenUri: nftResponse.tokenUri,
supply: nftResponse.supply,
owner: nftResponse.owner,
}));

// we fix the supportedInterfaces property if it is undefined in the response but present in the request
Object.values(response.contracts).forEach((contract) => {
contract.supportedInterfaces = contract.supportedInterfaces ||
params.type ? [params.type?.toLowerCase() as string] : undefined;
contract.supportedInterfaces = contract.supportedInterfaces || (params.type ? [params.type.toLowerCase()] : undefined);
});

this.processNftContractsCalldata(response.contracts);
Expand Down Expand Up @@ -431,7 +435,7 @@ export default abstract class EVMChainSettings implements ChainSettings {
}

// ensure NFT contract calldata is an object
processNftContractsCalldata(contracts: Record<string, IndexerNftContract>) {
processNftContractsCalldata(contracts: Record<string, IndexerContract>) {
for (const contract of Object.values(contracts)) {
try {
contract.calldata = typeof contract.calldata === 'string' ? JSON.parse(contract.calldata) : contract.calldata;
Expand All @@ -444,7 +448,7 @@ export default abstract class EVMChainSettings implements ChainSettings {
// shape the raw data from the indexer into a format that can be used to construct NFTs
shapeNftRawData(
raw: GenericIndexerNft[],
contracts: Record<string, IndexerNftContract>,
contracts: Record<string, IndexerContract>,
): NftRawData[] {
const shaped = [] as NftRawData[];
for (const item_source of raw) {
Expand Down Expand Up @@ -718,4 +722,36 @@ export default abstract class EVMChainSettings implements ChainSettings {
return response.result as EvmBlockData;
});
}

// allowances

async fetchErc20Allowances(account: string, filter: IndexerAllowanceFilter): Promise<IndexerAllowanceResponseErc20> {
const params = {
...filter,
type: 'erc20',
all: true,
};
const response = await this.indexer.get(`v1/account/${account}/approvals`, { params });
return response.data as IndexerAllowanceResponseErc20;
}

async fetchErc721Allowances(account: string, filter: IndexerAllowanceFilter): Promise<IndexerAllowanceResponseErc721> {
const params = {
...filter,
type: 'erc721',
all: true,
};
const response = await this.indexer.get(`v1/account/${account}/approvals`, { params });
return response.data as IndexerAllowanceResponseErc721;
}

async fetchErc1155Allowances(account: string, filter: IndexerAllowanceFilter): Promise<IndexerAllowanceResponseErc1155> {
const params = {
...filter,
type: 'erc1155',
all: true,
};
const response = await this.indexer.get(`v1/account/${account}/approvals`, { params });
return response.data as IndexerAllowanceResponseErc1155;
}
}
2 changes: 2 additions & 0 deletions src/antelope/chains/chain-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const TELOS_ANALYTICS_EVENT_IDS = {
loginFailedWalletConnect: '9V4IV1BV',
loginSuccessfulWalletConnect: '2EG2OR3H',
};

export const ZERO_ADDRESS = '0x'.concat('0'.repeat(40));
37 changes: 20 additions & 17 deletions src/antelope/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ChainModel } from 'src/antelope/stores/chain';

import {
useAccountStore,
useAllowancesStore,
useBalancesStore,
useChainStore,
useContractStore,
Expand Down Expand Up @@ -90,20 +91,21 @@ export class Antelope {

get stores() {
return {
user: useUserStore(),
chain: useChainStore(),
account: useAccountStore(),
allowances: useAllowancesStore(),
balances: useBalancesStore(),
chain: useChainStore(),
contract: useContractStore(),
evm: useEVMStore(),
feedback: useFeedbackStore(),
history: useHistoryStore(),
nfts: useNftsStore(),
platform: usePlatformStore(),
profile: useProfileStore(),
resources: useResourcesStore(),
rex: useRexStore(),
tokens: useTokensStore(),
contract: useContractStore(),
balances: useBalancesStore(),
history: useHistoryStore(),
feedback: useFeedbackStore(),
platform: usePlatformStore(),
evm: useEVMStore(),
nfts: useNftsStore(),
user: useUserStore(),
};
}

Expand All @@ -128,19 +130,20 @@ export const installAntelope = (app: App) => {
};

export { useAccountStore } from 'src/antelope/stores/account';
export { useAllowancesStore } from 'src/antelope/stores/allowances';
export { useBalancesStore } from 'src/antelope/stores/balances';
export { useChainStore } from 'src/antelope/stores/chain';
export { useUserStore } from 'src/antelope/stores/user';
export { useContractStore } from 'src/antelope/stores/contract';
export { useEVMStore } from 'src/antelope/stores/evm';
export { useFeedbackStore } from 'src/antelope/stores/feedback';
export { useHistoryStore } from 'src/antelope/stores/history';
export { useNftsStore } from 'src/antelope/stores/nfts';
export { usePlatformStore } from 'src/antelope/stores/platform';
export { useProfileStore } from 'src/antelope/stores/profile';
export { useResourcesStore } from 'src/antelope/stores/resources';
export { useRexStore } from 'src/antelope/stores/rex';
export { useTokensStore } from 'src/antelope/stores/tokens';
export { useContractStore } from 'src/antelope/stores/contract';
export { useBalancesStore } from 'src/antelope/stores/balances';
export { useHistoryStore } from 'src/antelope/stores/history';
export { useFeedbackStore } from 'src/antelope/stores/feedback';
export { usePlatformStore } from 'src/antelope/stores/platform';
export { useEVMStore } from 'src/antelope/stores/evm';
export { useNftsStore } from 'src/antelope/stores/nfts';
export { useUserStore } from 'src/antelope/stores/user';

// this constant is used for a temporal workaround for the multi-context issue
// https://github.com/telosnetwork/telos-wallet/issues/582
Expand Down
2 changes: 2 additions & 0 deletions src/antelope/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { createInitFunction, createTraceFunction } from 'src/antelope/stores/fee
import { initFuelUserWrapper } from 'src/api/fuel';
import {
CURRENT_CONTEXT,
useAllowancesStore,
useBalancesStore,
useFeedbackStore,
useHistoryStore,
Expand Down Expand Up @@ -213,6 +214,7 @@ export const useAccountStore = defineStore(store_name, {
useHistoryStore().clearEvmNftTransfers();
useBalancesStore().clearBalances();
useNftsStore().clearNFTs();
useAllowancesStore().clearAllowances();

try {
localStorage.removeItem('network');
Expand Down
Loading

0 comments on commit fed530f

Please sign in to comment.