Skip to content

Commit

Permalink
fix: remove duplicate token ids in streams
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Nov 12, 2022
1 parent 01d7233 commit 0eeebb4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
18 changes: 9 additions & 9 deletions packages/meta-transactions/src/meta-contract.ts
@@ -1,9 +1,9 @@
import { Environment } from '@0xflair/common';
import {
ContractFqn,
ContractVersion,
LATEST_VERSION,
loadContract,
ContractVersion,
} from '@0xflair/contracts-registry';
import { Provider } from '@ethersproject/providers';
import {
Expand All @@ -22,7 +22,7 @@ function buildMetaTransaction(
chainId: number,
metaTransactionsClient: MetaTransactionsClient,
contract: Contract,
fragment: FunctionFragment
fragment: FunctionFragment,
): ContractFunction<MetaTransaction> {
return async function (...args: Array<any>): Promise<MetaTransaction> {
const from = await contract.signer.getAddress();
Expand All @@ -37,7 +37,7 @@ function buildMetaTransaction(
}

export class MetaContract<
T extends EthersContract = EthersContract
T extends EthersContract = EthersContract,
> extends EthersContract {
readonly metaTransaction:
| { [name: string]: ContractFunction<any> }
Expand All @@ -49,22 +49,22 @@ export class MetaContract<
contractFqn: ContractFqn,
contractVersion: ContractVersion = LATEST_VERSION,
addressOrName?: string,
signerOrProvider?: Signer | Provider
signerOrProvider?: Signer | Provider,
) {
const contractDefinition = loadContract(contractFqn, contractVersion);
const contractAddressOrName =
addressOrName || contractDefinition.address?.[String(chainId)];

if (!contractAddressOrName) {
throw new Error(
`Could not determine contract address from constructor (${addressOrName}) nor from definition (${contractDefinition.address})`
`Could not determine contract address from constructor (${addressOrName}) nor from definition (${contractDefinition.address})`,
);
}

super(
contractAddressOrName,
contractDefinition.artifact.abi,
signerOrProvider
signerOrProvider,
);

this.metaTransaction = {};
Expand All @@ -75,7 +75,7 @@ export class MetaContract<
defineReadOnly<any, any>(
this.metaTransaction,
signature,
buildMetaTransaction(chainId, metaTransactionsClient, this, fragment)
buildMetaTransaction(chainId, metaTransactionsClient, this, fragment),
);
}

Expand All @@ -85,7 +85,7 @@ export class MetaContract<
defineReadOnly<any, any>(
this.metaTransaction,
name,
buildMetaTransaction(chainId, metaTransactionsClient, this, fragment)
buildMetaTransaction(chainId, metaTransactionsClient, this, fragment),
);
}
});
Expand All @@ -112,7 +112,7 @@ export class MetaContract<
config.contractFqn,
config.contractVersion,
config.addressOrName,
config.signerOrProvider
config.signerOrProvider,
) as unknown as T;
}
}
Expand Up @@ -117,7 +117,7 @@ export const useStreamTokensInCustody = (config: Config) => {
for (
let i = 0, l = Number(totalSupply?.toString() || 20_000);
i <= l;
i = i + 500
i = i + 500 + 1
) {
custodyStatusesPromises.push(fetchTokensInCustodyInRange(i, i + 500));
}
Expand Down
10 changes: 8 additions & 2 deletions packages/react-token-streams/src/providers/StreamProvider.tsx
Expand Up @@ -201,11 +201,17 @@ export const StreamProvider = ({
const ticketTokens = useMemo(() => {
return _.uniqBy(
[
...(walletNfts || []),
...(walletNfts || []).map(
(token) =>
({
...token,
tokenId: BigNumber.from(token.tokenId).toString(),
} as NftToken),
),
...(tokenIdsInCustody || []).map(
(tokenId) =>
({
tokenId,
tokenId: BigNumber.from(tokenId).toString(),
contractAddress: ticketTokenAddress,
ownerAddress: stream?.contractAddress,
} as NftToken),
Expand Down

0 comments on commit 0eeebb4

Please sign in to comment.