-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53497ef
commit 6764a3e
Showing
9 changed files
with
123 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Contract } from '@ethersproject/contracts'; | ||
import { Bicho as BichoContract } from '../../abi/types/Bicho'; | ||
import BichoABI from '../../abi/Bicho.json'; | ||
import getProvider from './getProvider'; | ||
|
||
declare const BICHO_ADDRESS: string; | ||
|
||
let contract: Promise<BichoContract>; | ||
|
||
const getContract = async () => { | ||
const provider = await getProvider(); | ||
return new Contract(BICHO_ADDRESS, BichoABI, provider) as BichoContract; | ||
}; | ||
|
||
export default async () => { | ||
contract ??= getContract(); | ||
return contract; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { DecentralandInterface } from 'decentraland-ecs'; | ||
import { Web3Provider, TransactionResponse } from '@ethersproject/providers'; | ||
|
||
declare const dcl: DecentralandInterface; | ||
|
||
class DCLProvider extends Web3Provider { | ||
// eslint-disable-next-line class-methods-use-this | ||
async getTransaction(hash: string | Promise<string>) { | ||
return { hash: await hash } as TransactionResponse; | ||
} | ||
} | ||
|
||
let provider: Promise<DCLProvider>; | ||
|
||
const getProvider = async () => { | ||
const { rpcHandle } = await dcl.loadModule('web3-provider'); | ||
return new DCLProvider(await dcl.callRpc(rpcHandle, 'getProvider', [])); | ||
}; | ||
|
||
export default async () => { | ||
provider ??= getProvider(); | ||
return provider; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DecentralandInterface } from 'decentraland-ecs'; | ||
|
||
declare const dcl: DecentralandInterface; | ||
|
||
let address: Promise<string>; | ||
|
||
const getAddress = async () => { | ||
const { rpcHandle } = await dcl.loadModule('Identity'); | ||
return await dcl.callRpc(rpcHandle, 'getUserPublicKey', []) as string; | ||
}; | ||
|
||
export default async () => { | ||
address ??= getAddress(); | ||
return address; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BichoType } from '../Bicho'; | ||
import getBichoContract from './getBichoContract'; | ||
import getUserAddress from './getUserAddress'; | ||
|
||
export default async () => { | ||
const [address, contract] = await Promise.all([getUserAddress(), getBichoContract()]); | ||
if (!address) return null; | ||
const balances = await contract.balanceOfBatch( | ||
Array(25).fill(address), | ||
Array(25).fill(null).map((_, i) => i), | ||
); | ||
return balances | ||
.map((balance, id) => ({ id, balance })) | ||
.filter(({ balance }) => !balance.isZero()) | ||
.map(({ id }) => id % BichoType.COUNT as BichoType); | ||
}; |