Skip to content

Commit

Permalink
Merge pull request #81 from bosonprotocol/80-opensea-link-issue
Browse files Browse the repository at this point in the history
fix opensea link and upgrade the boson configuration to allow using E…
  • Loading branch information
levalleux-ludo authored Oct 31, 2023
2 parents 4e2af1e + 504a9a2 commit 4e090fc
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 309 deletions.
53 changes: 48 additions & 5 deletions docs/dcl-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,63 @@

Please refer to [DCL-Edit Install Instructions](https://dcl-edit.com/install-guide)

## Edit the scene with DCL-Edit
## Create a Decentraland scene project

With DCL-Edit, you can place and manipulate objects in your scene just like in any other state-of-the-art game engine.
If you don't have a DCL scene project yet, create one

Launch DCL-Edit from your scene folder:
- create an empty folder
- go into this new folder
- run the following command
```
dcl init -p scene
```

## Install @bosonprotocol/boson-dcl and their dependencies

In your scene project folder, run npm to install @bosonprotocol/boson-dcl library and some required dependencies in your scene

```bash
npm install -D eth-connect patch-package
```
dcl-edit

```bash
npm install @dcl/crypto-scene-utils @dcl/ecs-scene-utils
```

### Note:
```bash
npm install @bosonprotocol/boson-dcl
```

Once you have added all dependencies in your scene project, please launch the build to finish initializing it:
```bash
dcl build
```

### Notes:
- You may have some building errors, that are removed by adding some compiler configuration properties in the `tsconfig.json` file
```ts
{
"compilerOptions": {
...
"skipLibCheck": true
},
...
}

```
- The complete example code created for your scene at this stage (in `./src/game.ts`) can be removed, as you won't probably use it.

Instead, you will be asked to call the SceneFactory method generated by DCL-Edit when you'll save your scene (details given in the next steps).

## Edit the scene with DCL-Edit

With DCL-Edit, you can place and manipulate objects in your scene just like in any other state-of-the-art game engine.

Launch DCL-Edit from your scene folder:
```
dcl-edit
```

### Add a BosonConfigurator component

This component is required to initialize the **@bosonprotocol/boson-dcl** library with the correct configuration.
Expand Down
7 changes: 5 additions & 2 deletions library/docs/boson-dcl.getenvironment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
<b>Signature:</b>

```typescript
export declare function getEnvironment(): EnvironmentType;
export declare function getEnvironment(): {
envName: EnvironmentType;
configId: ConfigId;
};
```
<b>Returns:</b>

EnvironmentType
{ envName: EnvironmentType; configId: ConfigId; }

5 changes: 4 additions & 1 deletion library/etc/boson-dcl.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export function getBalanceByCurrency(token: Token, walletAddress: string): Promi
export function getBalanceDecimalised(address: string): Promise<number>;

// @public (undocumented)
export function getEnvironment(): EnvironmentType;
export function getEnvironment(): {
envName: EnvironmentType;
configId: ConfigId;
};

// @public (undocumented)
export function getEthPrice(_query: TemplateStringsArray): Promise<any>;
Expand Down
28 changes: 25 additions & 3 deletions library/src/core-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EnvironmentType,
ConfigId,
subgraph,
getEnvConfigById,
} from "@bosonprotocol/core-sdk";
import { Delay } from "./ecs-utils-clone/delay";
import {
Expand All @@ -27,7 +28,8 @@ import { getUserData } from "@decentraland/Identity";

let httpRM: RequestManager;
let tokensList: Token[] | undefined;
let specifiedEnv: EnvironmentType;
let specifiedEnvName: EnvironmentType;
let specifiedConfigId: ConfigId;
let specifiedInventory: string[];
/**
* @public
Expand Down Expand Up @@ -60,6 +62,8 @@ export async function initCoreSdk(
httpRM = new RequestManager(provider);
// TODO: tokensList should be passed in configuration, independently from biconomy config
tokensList = bosonConfigs[envName]?.biconomy?.apiIds.tokens;
specifiedEnvName = envName;
specifiedConfigId = configId;
specifiedInventory = inventory;
const ethConnectAdapter = new EthConnectAdapter(
httpRM,
Expand All @@ -84,15 +88,30 @@ export async function initCoreSdk2(
inventory: string[]
): Promise<CoreSDK> {
const { envName, configId, biconomy, providerUrl } = bosonConfiguration;
const coreSdkConfig = getEnvConfigById(envName, configId);
if (!coreSdkConfig) {
throw new Error(
`Invalid coreSDK configuration (envName: ${envName}, configId: ${configId})`
);
}
const metaTx = biconomy
? processBiconomyConfig(envName, configId, biconomy)
: undefined;

const signer = await getProvider();
const metamaskRM = new RequestManager(signer);
const chainId = await metamaskRM.net_version();
if (!metaTx && chainId !== String(coreSdkConfig.chainId)) {
throw new Error(
`Wallet must be connected to chainId ${coreSdkConfig.chainId} (current: ${chainId}), or meta-transactions should be activated for this chain`
);
}

const provider: HTTPProvider = new HTTPProvider(providerUrl);
httpRM = new RequestManager(provider);
tokensList = _tokensList;
specifiedEnvName = envName;
specifiedConfigId = configId;
specifiedInventory = inventory;
const ethConnectAdapter = new EthConnectAdapter(
httpRM,
Expand Down Expand Up @@ -448,6 +467,9 @@ export function getTokenData(
return result;
}

export function getEnvironment(): EnvironmentType {
return specifiedEnv;
export function getEnvironment(): {
envName: EnvironmentType;
configId: ConfigId;
} {
return { envName: specifiedEnvName, configId: specifiedConfigId };
}
45 changes: 34 additions & 11 deletions library/src/scene/kiosk/pages/completePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ export class CompletePage {
openseaUrlBase = "";
bosonDAppUrlBase = "";

constructor(
_kiosk: ProductHandle,
_parent: Entity,
_productData: any
) {
constructor(_kiosk: ProductHandle, _parent: Entity, _productData: any) {
this.kiosk = _kiosk;
this.productData = _productData;

Expand Down Expand Up @@ -233,22 +229,40 @@ export class CompletePage {
})
);

switch (getEnvironment()) {
const { envName, configId } = getEnvironment();
switch (envName) {
case "local":
this.bosonDAppUrlBase = "http://localhost:3000";
break;
case "testing":
this.explorerUrlBase = "https://mumbai.polygonscan.com";
this.openseaUrlBase = "https://testnets.opensea.io/assets/mumbai";
this.bosonDAppUrlBase = "https://interface-test.on.fleek.co";
break;
case "staging":
this.explorerUrlBase = "https://mumbai.polygonscan.com";
this.openseaUrlBase = "https://testnets.opensea.io/assets/mumbai";
this.bosonDAppUrlBase = "https://interface-staging.on.fleek.co";
break;
case "production":
this.bosonDAppUrlBase = "https://bosonapp.io";
break;
}
switch (configId) {
case "local-31337-0":
case "testing-80001-0":
case "staging-80001-0":
this.explorerUrlBase = "https://mumbai.polygonscan.com";
this.openseaUrlBase = "https://testnets.opensea.io/assets/mumbai";
break;
case "testing-5-0":
case "staging-5-0":
this.explorerUrlBase = "https://goerli.etherscan.io";
this.openseaUrlBase = "https://testnets.opensea.io/assets/goerli";
break;
case "production-137-0":
this.explorerUrlBase = "https://polygonscan.com";
this.openseaUrlBase = "https://opensea.io/assets/matic";
this.bosonDAppUrlBase = "https://bosonapp.io";
break;
case "production-1-0":
this.explorerUrlBase = "https://etherscan.io";
this.openseaUrlBase = "https://opensea.io/assets/ethereum";
break;
}

Expand Down Expand Up @@ -312,6 +326,15 @@ export class CompletePage {
this.openSeaLinkClickBox.addComponentOrReplace(
new OnPointerDown(
() => {
log("openseaUrlBase", this.openseaUrlBase);
log(
"openseaUrl",
this.openseaUrlBase +
"/" +
productData.seller.voucherCloneAddress +
"/" +
tokenId
);
openExternalURL(
this.openseaUrlBase +
"/" +
Expand Down
3 changes: 2 additions & 1 deletion library/src/scene/kiosk/pages/fairExchangePolicyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ export class FairExchangePolicyPage {
// Click boxes

let URLBase = "";
const { envName } = getEnvironment();

switch (getEnvironment()) {
switch (envName) {
case "local":
case "testing":
URLBase = "https://interface-test.on.fleek.co/";
Expand Down
47 changes: 15 additions & 32 deletions scene/src/boson.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import { initCoreSdk } from '@bosonprotocol/boson-dcl'
import { getUserData, UserData } from '@decentraland/Identity'
import { BosonConfigurator } from '@bosonprotocol/boson-dcl'
import { bosonConfig } from './bosonConfig'
import * as crypto from '@dcl/crypto-scene-utils'
import { getProvider } from '@decentraland/web3-provider'
import { RequestManager } from 'eth-connect'

// const targetEnv = 'production'
// const targetEnv = 'staging'
// const targetEnv = 'testing'

async function getWalletAddress(): Promise<string> {
return await getUserData()
.then((userAccount) => {
return userAccount?.publicKey || (userAccount?.userId as string)
})
.catch((error) => {
log(error)
return ''
})
}

export async function useBoson() {
const provider = await getProvider()
const requestManager = new RequestManager(provider)
const chainId = await requestManager.net_version()
log('chainId', chainId)
// If user wallet is connected on Ethereum mainnet --> PRODUCTION
const targetEnv = chainId === '1' ? 'production' : 'staging'
const configId = chainId === '1' ? 'production-137-0' : 'staging-80001-0'
log('Initialize BOSON on env', targetEnv, 'config', configId)
const userAccount: UserData = (await getUserData()) as UserData
const productionConfigId = 'production-137-0' // polygon
// const productionConfigId = 'production-1-0' // ethereum
const productionBosonConfig = bosonConfig[productionConfigId]
if (!productionBosonConfig) {
throw new Error(`Unable to get bosonConfig for configId ${productionConfigId}`)
}
const stagingConfigId = 'staging-80001-0' // mumbai
// const stagingConfigId = 'staging-5-0' // goerli
const stagingBosonConfig = bosonConfig[stagingConfigId]
if (!stagingBosonConfig) {
throw new Error(`Unable to get bosonConfig for configId ${stagingConfigId}`)
}

const walletAddress = userAccount?.publicKey || userAccount?.userId
let inventory: string[] = [];
let inventory: string[] = []
try {
inventory = await crypto.avatar.getUserInventory()
} catch (e) {}
const coreSDK = await initCoreSdk(targetEnv, configId, bosonConfig, getWalletAddress, inventory)

return { coreSDK, userAccount, walletAddress, targetEnv, configId }
return BosonConfigurator.initialize(productionBosonConfig, stagingBosonConfig, inventory)
}
60 changes: 18 additions & 42 deletions scene/src/bosonConfig.example.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
import { BosonConfigs } from '@bosonprotocol/boson-dcl'
import { BosonConfiguration } from '@bosonprotocol/boson-dcl'

export const bosonConfig: BosonConfigs = {
testing: {
// mumbai
biconomy: {
apiKey: 'testing-project-api-key',
apiIds: {
protocol: {
method: 'executeMetaTransaction',
apiId: 'testing-project-protocol-api-id'
},
tokens: [
{
// boson
name: 'boson',
address: '0x1f5431e8679630790e8eba3a9b41d1bb4d41aed0',
method: 'executeMetaTransaction',
apiId: 'testing-project-boson-token-api-id'
},
{
// weth
name: 'weth',
address: '0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa',
method: 'executeMetaTransaction',
apiId: 'testing-project-weth-token-api-id'
},
{
// usdc
name: 'usdc',
address: '0xe6b8a5cf854791412c1f6efc7caf629f5df1c747',
method: 'executeMetaTransaction',
apiId: 'testing-project-usdc-token-api-id'
}
]
}
},
providerUrl: 'mumbai-rpc-node'
},
staging: {
// mumbai
export const bosonConfig: { [key: string]: BosonConfiguration } = {
'staging-80001-0': {
envName: 'staging',
configId: 'staging-80001-0',
biconomy: {
apiKey: 'staging-project-api-key',
apiIds: {
Expand Down Expand Up @@ -73,8 +38,14 @@ export const bosonConfig: BosonConfigs = {
},
providerUrl: 'mumbai-rpc-node'
},
production: {
// polygon
'staging-5-0': {
envName: 'staging',
configId: 'staging-5-0',
providerUrl: 'goerli-rpc-node'
},
'production-137-0': {
envName: 'production',
configId: 'production-137-0',
biconomy: {
apiKey: 'production-project-api-key',
apiIds: {
Expand Down Expand Up @@ -122,5 +93,10 @@ export const bosonConfig: BosonConfigs = {
}
},
providerUrl: 'polygon-rpc-node'
},
'production-1-0': {
envName: 'production',
configId: 'production-1-0',
providerUrl: 'ethereum-rpc-node'
}
}
Loading

0 comments on commit 4e090fc

Please sign in to comment.