移除一些无用代码,合约地址的配置改为根据链id和环境获取
This commit is contained in:
parent
f8498487ba
commit
a316fc750f
50
src/config/cfg_421613_dev.js
Normal file
50
src/config/cfg_421613_dev.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
module.exports = {
|
||||||
|
tokens: [
|
||||||
|
{
|
||||||
|
type: "eth",
|
||||||
|
address: "eth",
|
||||||
|
symbol: "MATIC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0xfa513999031dC1DCf86e99d91101e17d07839236",
|
||||||
|
symbol: "CEC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0x9f87eCA8F0479383fF11a5AB2336b5A6c383d6F3",
|
||||||
|
symbol: "CEG",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x3EBF5196dADC8F3F09C808333f98FE8A4b7d1e62",
|
||||||
|
name: "hero",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x2F2Ed1c403cB7156617449795dE1CB47A0302a25",
|
||||||
|
name: "weapon",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x73482411443E87CAC124C12A10B34e9Aaa2De168",
|
||||||
|
name: "chip",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0xFc21A863bFb4E4534B246078772e2074e076f0a7",
|
||||||
|
name: "shard",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
contracts: {
|
||||||
|
nftMall: "0x1F6293c44633a50311Ec5Ab02ff14034b5c31272",
|
||||||
|
evolveFactory: "0x9e6167B11Ad15D8407865E21D4770E9F6CF10853",
|
||||||
|
minterFactory: "0xb60c7312F56da4303CE3bf27124f1850dBe1D0E5",
|
||||||
|
chipLocker: "0x4Ef766854EE104053cF2D243620b7A643fCC2B54",
|
||||||
|
nftFactory: "0xEA374dC9f94E7A3A2eE8C0C910954cE15E2C469E",
|
||||||
|
market: "0x806eA3301c2bA2a3C710D97931a6C0Fe00E45B33",
|
||||||
|
},
|
||||||
|
};
|
50
src/config/cfg_421613_release.js
Normal file
50
src/config/cfg_421613_release.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
module.exports = {
|
||||||
|
tokens: [
|
||||||
|
{
|
||||||
|
type: "eth",
|
||||||
|
address: "eth",
|
||||||
|
symbol: "MATIC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0xfa513999031dC1DCf86e99d91101e17d07839236",
|
||||||
|
symbol: "CEC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0x9f87eCA8F0479383fF11a5AB2336b5A6c383d6F3",
|
||||||
|
symbol: "CEG",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x3EBF5196dADC8F3F09C808333f98FE8A4b7d1e62",
|
||||||
|
name: "hero",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x2F2Ed1c403cB7156617449795dE1CB47A0302a25",
|
||||||
|
name: "weapon",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x73482411443E87CAC124C12A10B34e9Aaa2De168",
|
||||||
|
name: "chip",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0xFc21A863bFb4E4534B246078772e2074e076f0a7",
|
||||||
|
name: "shard",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
contracts: {
|
||||||
|
nftMall: "0x1F6293c44633a50311Ec5Ab02ff14034b5c31272",
|
||||||
|
evolveFactory: "0x9e6167B11Ad15D8407865E21D4770E9F6CF10853",
|
||||||
|
minterFactory: "0xb60c7312F56da4303CE3bf27124f1850dBe1D0E5",
|
||||||
|
chipLocker: "0x4Ef766854EE104053cF2D243620b7A643fCC2B54",
|
||||||
|
nftFactory: "0xEA374dC9f94E7A3A2eE8C0C910954cE15E2C469E",
|
||||||
|
market: "0x806eA3301c2bA2a3C710D97931a6C0Fe00E45B33",
|
||||||
|
},
|
||||||
|
};
|
50
src/config/cfg_80001_dev.js
Normal file
50
src/config/cfg_80001_dev.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
module.exports = {
|
||||||
|
tokens: [
|
||||||
|
{
|
||||||
|
type: "eth",
|
||||||
|
address: "eth",
|
||||||
|
symbol: "MATIC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0xfa513999031dC1DCf86e99d91101e17d07839235",
|
||||||
|
symbol: "CEC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0x9f87eCA8F0479383fF11a5AB2336b5A6c383d6F3",
|
||||||
|
symbol: "CEG",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x3EBF5196dADC8F3F09C808333f98FE8A4b7d1e62",
|
||||||
|
name: "hero",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x2F2Ed1c403cB7156617449795dE1CB47A0302a25",
|
||||||
|
name: "weapon",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x73482411443E87CAC124C12A10B34e9Aaa2De168",
|
||||||
|
name: "chip",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0xFc21A863bFb4E4534B246078772e2074e076f0a7",
|
||||||
|
name: "shard",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
contracts: {
|
||||||
|
nftMall: "0x1F6293c44633a50311Ec5Ab02ff14034b5c31272",
|
||||||
|
evolveFactory: "0x9e6167B11Ad15D8407865E21D4770E9F6CF10853",
|
||||||
|
minterFactory: "0xb60c7312F56da4303CE3bf27124f1850dBe1D0E5",
|
||||||
|
chipLocker: "0x4Ef766854EE104053cF2D243620b7A643fCC2B54",
|
||||||
|
nftFactory: "0xEA374dC9f94E7A3A2eE8C0C910954cE15E2C469E",
|
||||||
|
market: "0x806eA3301c2bA2a3C710D97931a6C0Fe00E45B33",
|
||||||
|
},
|
||||||
|
};
|
50
src/config/cfg_80001_release.js
Normal file
50
src/config/cfg_80001_release.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
module.exports = {
|
||||||
|
tokens: [
|
||||||
|
{
|
||||||
|
type: "eth",
|
||||||
|
address: "eth",
|
||||||
|
symbol: "MATIC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0xfa513999031dC1DCf86e99d91101e17d07839235",
|
||||||
|
symbol: "CEC",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "erc20",
|
||||||
|
address: "0x9f87eCA8F0479383fF11a5AB2336b5A6c383d6F3",
|
||||||
|
symbol: "CEG",
|
||||||
|
decimal: 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x3EBF5196dADC8F3F09C808333f98FE8A4b7d1e62",
|
||||||
|
name: "hero",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x2F2Ed1c403cB7156617449795dE1CB47A0302a25",
|
||||||
|
name: "weapon",
|
||||||
|
type: "erc721",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x73482411443E87CAC124C12A10B34e9Aaa2De168",
|
||||||
|
name: "chip",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0xFc21A863bFb4E4534B246078772e2074e076f0a7",
|
||||||
|
name: "shard",
|
||||||
|
type: "erc1155",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
contracts: {
|
||||||
|
nftMall: "0x1F6293c44633a50311Ec5Ab02ff14034b5c31272",
|
||||||
|
evolveFactory: "0x9e6167B11Ad15D8407865E21D4770E9F6CF10853",
|
||||||
|
minterFactory: "0xb60c7312F56da4303CE3bf27124f1850dBe1D0E5",
|
||||||
|
chipLocker: "0x4Ef766854EE104053cF2D243620b7A643fCC2B54",
|
||||||
|
nftFactory: "0xEA374dC9f94E7A3A2eE8C0C910954cE15E2C469E",
|
||||||
|
market: "0x806eA3301c2bA2a3C710D97931a6C0Fe00E45B33",
|
||||||
|
},
|
||||||
|
};
|
@ -1,237 +0,0 @@
|
|||||||
export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/";
|
|
||||||
|
|
||||||
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
|
|
||||||
|
|
||||||
export const DEFALUT_TOKENS = {
|
|
||||||
321: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "KCS",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0xcaA011E902103752435AC98657B046B282E36509",
|
|
||||||
symbol: "CEC",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0xBE023C9D294A4668f0d510E2570CB81B4536cE77",
|
|
||||||
symbol: "CEG",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
322: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "tKCS",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0xdb6D4bB22E2C12686Efff25a79EC78f9f078fe7D",
|
|
||||||
symbol: "CEC",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0xC5Cd606b3e9B80b758e8274B198c76D929aA094A",
|
|
||||||
symbol: "CEG",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
97: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "BNB",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
56: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "BNB",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
137: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "MATIC",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
80001: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "MATIC",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0xfa513999031dC1DCf86e99d91101e17d07839235",
|
|
||||||
symbol: "CEC",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0x9f87eCA8F0479383fF11a5AB2336b5A6c383d6F3",
|
|
||||||
symbol: "CEG",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
1338: [
|
|
||||||
{
|
|
||||||
type: "eth",
|
|
||||||
address: "eth",
|
|
||||||
symbol: "ETH",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7",
|
|
||||||
symbol: "CEC",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "erc20",
|
|
||||||
address: "0x59d3631c86BbE35EF041872d502F218A39FBa150",
|
|
||||||
symbol: "CEG",
|
|
||||||
decimal: 18,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DEFAULT_NFT_TYPES = {
|
|
||||||
321: {
|
|
||||||
hero: {
|
|
||||||
address: "0x0EB362BD40F2288fF25A6Ee1b487cB0cb4638e0D",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
weapon: {
|
|
||||||
address: "0x29F67A372AC1c6AcF478A564992D421FE20F2cc8",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
chip: {
|
|
||||||
address: "0x54B6ED7EDe9355b471985439421Aa1DC7Da6Dc20",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
shard: {
|
|
||||||
address: "0x54B6ED7EDe9355b471985439421Aa1DC7Da6Dc20",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
322: {
|
|
||||||
hero: {
|
|
||||||
address: "0x52917087cd4E48bDb5f336012E677f471f9E1C2D",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
weapon: {
|
|
||||||
address: "0x500AD8A4D50d71Af5cA8eA3b12B914f7aE5466f7",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
chip: {
|
|
||||||
address: "0x0640958BDb4D7956e1452FacEBD550C6Cf42aC94",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
shard: {
|
|
||||||
address: "0x54B6ED7EDe9355b471985439421Aa1DC7Da6Dc20",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
137: {
|
|
||||||
hero: {
|
|
||||||
address: "0xaE08adb5278B107D2501e7c61907e41FEf3887D7",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
weapon: {
|
|
||||||
address: "0xee0044BF2ACEf7C3D7f6781d8f5DC4d2Dd1CE64c",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
chip: {
|
|
||||||
address: "0xc058411B15E544291765F15B13c88582b7bceaD0",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
shard: {
|
|
||||||
address: "0x1d4c7908E6a6795aE4335D0F072B0A129AAFFdc1",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
80001: {
|
|
||||||
hero: {
|
|
||||||
address: "0x3EBF5196dADC8F3F09C808333f98FE8A4b7d1e62",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
weapon: {
|
|
||||||
address: "0x2F2Ed1c403cB7156617449795dE1CB47A0302a25",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
chip: {
|
|
||||||
address: "0x73482411443E87CAC124C12A10B34e9Aaa2De168",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
shard: {
|
|
||||||
address: "0xFc21A863bFb4E4534B246078772e2074e076f0a7",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
1338: {
|
|
||||||
hero: {
|
|
||||||
address: "0x9b1f7F645351AF3631a656421eD2e40f2802E6c0",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
weapon: {
|
|
||||||
address: "0x2612Af3A521c2df9EAF28422Ca335b04AdF3ac66",
|
|
||||||
type: "erc721",
|
|
||||||
},
|
|
||||||
chip: {
|
|
||||||
address: "0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
shard: {
|
|
||||||
address: "0x0E696947A06550DEf604e82C26fd9E493e576337",
|
|
||||||
type: "erc1155",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const JC_CONTRACTS = {
|
|
||||||
321: {
|
|
||||||
nftMall: "0xa44927698D0aC8EF29e91508839cd6e10f773EE0",
|
|
||||||
evolveFactory: "0x07Bad070e403a4Bad2Eec3BA3894c4524d3d2674",
|
|
||||||
minterFactory: "0x5ecEFA2707e3f09B9A169ae696B36Df8dB7410ED",
|
|
||||||
},
|
|
||||||
322: {
|
|
||||||
nftMall: "0xa44927698D0aC8EF29e91508839cd6e10f773EE0",
|
|
||||||
evolveFactory: "0x07Bad070e403a4Bad2Eec3BA3894c4524d3d2674",
|
|
||||||
minterFactory: "0x5ecEFA2707e3f09B9A169ae696B36Df8dB7410ED",
|
|
||||||
},
|
|
||||||
137: {
|
|
||||||
nftMall: "0xa44927698D0aC8EF29e91508839cd6e10f773EE0",
|
|
||||||
evolveFactory: "0x07Bad070e403a4Bad2Eec3BA3894c4524d3d2674",
|
|
||||||
minterFactory: "0x5ecEFA2707e3f09B9A169ae696B36Df8dB7410ED",
|
|
||||||
},
|
|
||||||
80001: {
|
|
||||||
nftMall: "0x1F6293c44633a50311Ec5Ab02ff14034b5c31272",
|
|
||||||
evolveFactory: "0x9e6167B11Ad15D8407865E21D4770E9F6CF10853",
|
|
||||||
minterFactory: "0xb60c7312F56da4303CE3bf27124f1850dBe1D0E5",
|
|
||||||
chipLocker: "0x4Ef766854EE104053cF2D243620b7A643fCC2B54",
|
|
||||||
nftFactory: "0xEA374dC9f94E7A3A2eE8C0C910954cE15E2C469E", // for minterFactory call
|
|
||||||
market: "0x806eA3301c2bA2a3C710D97931a6C0Fe00E45B33",
|
|
||||||
},
|
|
||||||
1338: {
|
|
||||||
nftMall: "0x5017A545b09ab9a30499DE7F431DF0855bCb7275",
|
|
||||||
evolveFactory: "0xaD888d0Ade988EbEe74B8D4F39BF29a8d0fe8A8D",
|
|
||||||
minterFactory: "0x6eD79Aa1c71FD7BdBC515EfdA3Bd4e26394435cC",
|
|
||||||
chipLocker: "0xFF6049B87215476aBf744eaA3a476cBAd46fB1cA",
|
|
||||||
nftFactory: "0xA94B7f0465E98609391C623d0560C5720a3f2D33", // for minterFactory call
|
|
||||||
market: "0xFC628dd79137395F3C9744e33b1c5DE554D94882",
|
|
||||||
},
|
|
||||||
};
|
|
@ -14,3 +14,5 @@ export const NATIVE_PK_PREFIX = "0x000000000000000000000000";
|
|||||||
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
||||||
|
|
||||||
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
|
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
|
||||||
|
|
||||||
|
export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/";
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
import { DEFALUT_TOKENS } from "../config/chain_config";
|
|
||||||
|
|
||||||
export interface IToken {
|
|
||||||
address: string;
|
|
||||||
type: "eth" | "erc20";
|
|
||||||
default: boolean;
|
|
||||||
symbol?: string;
|
|
||||||
balance?: string;
|
|
||||||
decimal: number;
|
|
||||||
image?: string;
|
|
||||||
last?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface INFT {
|
|
||||||
address: string;
|
|
||||||
type: "erc721" | "erc1155";
|
|
||||||
index: number;
|
|
||||||
tokenId?: string;
|
|
||||||
image?: string;
|
|
||||||
name?: string;
|
|
||||||
desc?: string;
|
|
||||||
last?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initNFT(address: string, index: number, type: 'erc721'|'erc1155') {
|
|
||||||
return {
|
|
||||||
address,
|
|
||||||
index,
|
|
||||||
type
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ITokenData {
|
|
||||||
tokens: IToken[];
|
|
||||||
heros: INFT[];
|
|
||||||
weapons: INFT[];
|
|
||||||
chips: INFT[];
|
|
||||||
}
|
|
||||||
export interface IAccount {
|
|
||||||
address: string;
|
|
||||||
type: number;
|
|
||||||
index: number;
|
|
||||||
nickname?: string;
|
|
||||||
avatar?: string;
|
|
||||||
tokenData: {
|
|
||||||
[key: number]: ITokenData;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initAccount({
|
|
||||||
address,
|
|
||||||
chain,
|
|
||||||
nickname,
|
|
||||||
type,
|
|
||||||
index
|
|
||||||
}: {
|
|
||||||
address: string;
|
|
||||||
chain: number;
|
|
||||||
nickname: string;
|
|
||||||
type: number,
|
|
||||||
index: number
|
|
||||||
}): IAccount {
|
|
||||||
let chainData = {};
|
|
||||||
let data: IAccount = {
|
|
||||||
address,
|
|
||||||
nickname,
|
|
||||||
type,
|
|
||||||
index,
|
|
||||||
tokenData: chainData,
|
|
||||||
};
|
|
||||||
let tokens = DEFALUT_TOKENS[chain];
|
|
||||||
chainData[chain] = {
|
|
||||||
tokens,
|
|
||||||
heros: [],
|
|
||||||
weapons: [],
|
|
||||||
chips: [],
|
|
||||||
};
|
|
||||||
return data;
|
|
||||||
}
|
|
227
src/index.ts
227
src/index.ts
@ -9,20 +9,17 @@ import {
|
|||||||
createWalletEvents,
|
createWalletEvents,
|
||||||
WALLET_ACCOUNT_CHANGE,
|
WALLET_ACCOUNT_CHANGE,
|
||||||
WALLET_CHAIN_CHANGE,
|
WALLET_CHAIN_CHANGE,
|
||||||
WALLET_TOKEN_TYPE_CHANGE,
|
|
||||||
} from "./common/WalletEvent";
|
} from "./common/WalletEvent";
|
||||||
import { JazzIcon } from "./comp/JazzIcon";
|
import { JazzIcon } from "./comp/JazzIcon";
|
||||||
import { ZWalletConnect } from "./comp/ZWalletConnect";
|
import { ZWalletConnect } from "./comp/ZWalletConnect";
|
||||||
import { AVAILABLE_CHAINS, DEFALUT_TOKENS } from "./config/chain_config";
|
|
||||||
import {
|
import {
|
||||||
|
AVAILABLE_CHAINS,
|
||||||
NATIVE_PK_PREFIX,
|
NATIVE_PK_PREFIX,
|
||||||
TX_CONFIRM_BLOCKS,
|
TX_CONFIRM_BLOCKS,
|
||||||
WALLET_STORAGE_KEY_NAME,
|
WALLET_STORAGE_KEY_NAME,
|
||||||
} from "./config/constants";
|
} from "./config/constants";
|
||||||
import { AllChains } from "./data/allchain";
|
import { AllChains } from "./data/allchain";
|
||||||
import { IAccount, INFT, initAccount, initNFT } from "./data/DataModel";
|
|
||||||
import { singleton } from "./decorator/singleton.decorator";
|
import { singleton } from "./decorator/singleton.decorator";
|
||||||
import { saveData } from "./manage/DataManage";
|
|
||||||
import { parseUrl } from "./manage/SchemeManage";
|
import { parseUrl } from "./manage/SchemeManage";
|
||||||
import {
|
import {
|
||||||
exportSecKey,
|
exportSecKey,
|
||||||
@ -42,12 +39,7 @@ import { ERC721Standard } from "./standards/ERC721Standard";
|
|||||||
import { JCStandard } from "./standards/JCStandard";
|
import { JCStandard } from "./standards/JCStandard";
|
||||||
import { WalletType } from "./types/data.enums";
|
import { WalletType } from "./types/data.enums";
|
||||||
import { IChainData } from "./types/data.types";
|
import { IChainData } from "./types/data.types";
|
||||||
import {
|
import { universalChainCb } from "./util/chain.util";
|
||||||
getJCErc721Info,
|
|
||||||
getTypeByAddress,
|
|
||||||
universalChainCb,
|
|
||||||
UNKNOW,
|
|
||||||
} from "./util/chain.util";
|
|
||||||
import { fromTokenMinimalUnit } from "./util/number.util";
|
import { fromTokenMinimalUnit } from "./util/number.util";
|
||||||
import { buildLoginSignMsg, signLogin } from "./util/sign.util";
|
import { buildLoginSignMsg, signLogin } from "./util/sign.util";
|
||||||
|
|
||||||
@ -78,14 +70,11 @@ export default class JCWallet {
|
|||||||
public paySvr: PaySvr;
|
public paySvr: PaySvr;
|
||||||
public wConnect: ZWalletConnect;
|
public wConnect: ZWalletConnect;
|
||||||
public mainHandlers = createWalletEvents();
|
public mainHandlers = createWalletEvents();
|
||||||
public data: IAccount[] = [];
|
|
||||||
public iconType = "jazz";
|
|
||||||
private accountIndex = 0;
|
|
||||||
private walletType: WalletType = WalletType.INTERNAL;
|
private walletType: WalletType = WalletType.INTERNAL;
|
||||||
private rpcUrl: string = "";
|
private rpcUrl: string = "";
|
||||||
public rpc: any = {};
|
public rpc: any = {};
|
||||||
public nativeAccount = "";
|
public nativeAccount = "";
|
||||||
public feeAddressMap: Map<string, string> = new Map();
|
private env = "dev";
|
||||||
|
|
||||||
constructor({ type }: { type: number }) {
|
constructor({ type }: { type: number }) {
|
||||||
this.nativeSvr = new NativeSvr();
|
this.nativeSvr = new NativeSvr();
|
||||||
@ -128,7 +117,12 @@ export default class JCWallet {
|
|||||||
return loginByEmail(email, password);
|
return loginByEmail(email, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initInternalWallet(chain: number, pass: string) {
|
public async initInternalWallet(
|
||||||
|
chain: number,
|
||||||
|
pass: string,
|
||||||
|
env: string = "dev"
|
||||||
|
) {
|
||||||
|
this.env = env;
|
||||||
this.walletType = WalletType.INTERNAL;
|
this.walletType = WalletType.INTERNAL;
|
||||||
this.updateChain(chain);
|
this.updateChain(chain);
|
||||||
let address: string = await loadInternalWallet(pass);
|
let address: string = await loadInternalWallet(pass);
|
||||||
@ -137,7 +131,7 @@ export default class JCWallet {
|
|||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
this.web3 = new Web3(this.rpcUrl);
|
this.web3 = new Web3(this.rpcUrl);
|
||||||
this.web3.eth.transactionConfirmationBlocks = TX_CONFIRM_BLOCKS;
|
this.web3.eth.transactionConfirmationBlocks = TX_CONFIRM_BLOCKS;
|
||||||
console.log(`init web3 cost: ${(Date.now() - start) / 1000}`);
|
console.log(`init web3 cost: ${(Date.now() - start) / 1000}s`);
|
||||||
this.erc20Standard = new ERC20Standard(this.web3);
|
this.erc20Standard = new ERC20Standard(this.web3);
|
||||||
console.log("init Erc20Standard");
|
console.log("init Erc20Standard");
|
||||||
this.erc721Standard = new ERC721Standard(this.web3);
|
this.erc721Standard = new ERC721Standard(this.web3);
|
||||||
@ -147,7 +141,7 @@ export default class JCWallet {
|
|||||||
this.jcStandard = new JCStandard(this.web3);
|
this.jcStandard = new JCStandard(this.web3);
|
||||||
this.chainCommon = new ChainCommon(this.web3);
|
this.chainCommon = new ChainCommon(this.web3);
|
||||||
console.log("init JCStandard");
|
console.log("init JCStandard");
|
||||||
this.createAccount();
|
this.injectAccount();
|
||||||
console.log(JSON.stringify(this.wallet[0]));
|
console.log(JSON.stringify(this.wallet[0]));
|
||||||
console.log(
|
console.log(
|
||||||
"this.web3.eth.defaultAccount: " +
|
"this.web3.eth.defaultAccount: " +
|
||||||
@ -158,7 +152,8 @@ export default class JCWallet {
|
|||||||
* init wallet connect
|
* init wallet connect
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async initThirdPartyWallet(chain: number) {
|
public async initThirdPartyWallet(chain: number, env: string = "dev") {
|
||||||
|
this.env = env;
|
||||||
this.walletType = WalletType.THIRD_PATH;
|
this.walletType = WalletType.THIRD_PATH;
|
||||||
this.updateChain(chain);
|
this.updateChain(chain);
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
@ -218,15 +213,16 @@ export default class JCWallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
// if (this.walletType !== WalletType.INTERNAL) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentChain() {
|
get currentChain() {
|
||||||
return this._currentChain;
|
return this._currentChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get currentChainCfg() {
|
||||||
|
return require(`./config/cfg_${this.currentChain.id}_${this.env}.js`);
|
||||||
|
}
|
||||||
|
|
||||||
updateCurrentChain(chainId: number) {
|
updateCurrentChain(chainId: number) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.walletType === WalletType.INTERNAL) {
|
if (this.walletType === WalletType.INTERNAL) {
|
||||||
@ -238,7 +234,6 @@ export default class JCWallet {
|
|||||||
this._currentChain = chainData;
|
this._currentChain = chainData;
|
||||||
this.web3.eth.setProvider(chainData.rpc);
|
this.web3.eth.setProvider(chainData.rpc);
|
||||||
this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData);
|
this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData);
|
||||||
this.updateListType("tokens");
|
|
||||||
resolve && resolve(this.currentChain);
|
resolve && resolve(this.currentChain);
|
||||||
} else {
|
} else {
|
||||||
console.log("third party wallet change chain: " + chainId);
|
console.log("third party wallet change chain: " + chainId);
|
||||||
@ -259,21 +254,18 @@ export default class JCWallet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateListType(type: string) {
|
|
||||||
this.mainHandlers.emit(WALLET_TOKEN_TYPE_CHANGE, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
get chainList() {
|
get chainList() {
|
||||||
return [...this.chainMap.values()];
|
return [...this.chainMap.values()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public currentAccount() {
|
public currentAccount() {
|
||||||
if (this.walletType === WalletType.INTERNAL) {
|
if (this.walletType === WalletType.INTERNAL) {
|
||||||
return this.wallet[this.accountIndex];
|
return this.wallet[0];
|
||||||
} else {
|
} else {
|
||||||
return this.wConnect.accounts[0];
|
return this.wConnect.accounts[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get currentAccAddr() {
|
public get currentAccAddr() {
|
||||||
if (this.walletType === WalletType.INTERNAL) {
|
if (this.walletType === WalletType.INTERNAL) {
|
||||||
return this.nativeAccount;
|
return this.nativeAccount;
|
||||||
@ -282,35 +274,8 @@ export default class JCWallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentAccountData() {
|
public injectAccount() {
|
||||||
let address = this.currentAccAddr;
|
|
||||||
const chain = this.currentChain.id;
|
|
||||||
let data = this.data.find((o) => o.address === address);
|
|
||||||
if (!data) {
|
|
||||||
throw new Error("account data not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data.tokenData[chain]) {
|
|
||||||
let tokens = DEFALUT_TOKENS[chain];
|
|
||||||
data.tokenData[chain] = {
|
|
||||||
tokens,
|
|
||||||
heros: [],
|
|
||||||
weapons: [],
|
|
||||||
chips: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
saveData(this.data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
get accounts() {
|
|
||||||
return this.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public createAccount() {
|
|
||||||
this.wallet = this.web3.eth.accounts.wallet;
|
this.wallet = this.web3.eth.accounts.wallet;
|
||||||
const index = this.getMaxIdexOfType(0);
|
|
||||||
const nativePrivateKey = `${NATIVE_PK_PREFIX}${this.currentAccAddr.slice(
|
const nativePrivateKey = `${NATIVE_PK_PREFIX}${this.currentAccAddr.slice(
|
||||||
2
|
2
|
||||||
)}`;
|
)}`;
|
||||||
@ -318,83 +283,11 @@ export default class JCWallet {
|
|||||||
const account = this.wallet.add(acc);
|
const account = this.wallet.add(acc);
|
||||||
this.web3.eth.defaultAccount = account.address;
|
this.web3.eth.defaultAccount = account.address;
|
||||||
console.log("web3 account: " + JSON.stringify(this.wallet[0]));
|
console.log("web3 account: " + JSON.stringify(this.wallet[0]));
|
||||||
|
|
||||||
this.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
this.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
||||||
const chain = this.currentChain.id;
|
|
||||||
let data = this.data.find((o) => o.address === account.address);
|
|
||||||
if (!data) {
|
|
||||||
const nickname = `Account ${index + 1}`;
|
|
||||||
data = initAccount({
|
|
||||||
address: account.address,
|
|
||||||
chain,
|
|
||||||
nickname,
|
|
||||||
type: 0,
|
|
||||||
index,
|
|
||||||
});
|
|
||||||
this.data.push(data);
|
|
||||||
saveData(this.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.accountIndex = this.wallet.length - 1;
|
|
||||||
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address);
|
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address);
|
||||||
return account.address;
|
return account.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public importAccount(privateKey: string) {
|
|
||||||
const account = this.wallet.add(privateKey);
|
|
||||||
const chain = this.currentChain.id;
|
|
||||||
let data = this.data.find((o) => o.address === account.address);
|
|
||||||
if (!data) {
|
|
||||||
const index = this.getMaxIdexOfType(1);
|
|
||||||
const nickname = `Imported ${index + 1}`;
|
|
||||||
data = initAccount({
|
|
||||||
address: account.address,
|
|
||||||
chain,
|
|
||||||
nickname,
|
|
||||||
type: 1,
|
|
||||||
index,
|
|
||||||
});
|
|
||||||
this.data.push(data);
|
|
||||||
saveData(this.data);
|
|
||||||
}
|
|
||||||
this.web3.eth.accounts.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
|
||||||
this.accountIndex = this.wallet.length - 1;
|
|
||||||
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address);
|
|
||||||
return account.address;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getMaxIdexOfType(type: number) {
|
|
||||||
let maxIdx = -1;
|
|
||||||
for (let i = 0, l = this.data.length; i < l; i++) {
|
|
||||||
if (this.data[i].type !== type) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
maxIdx = Math.max(this.data[i].index, maxIdx);
|
|
||||||
}
|
|
||||||
return maxIdx + 1;
|
|
||||||
}
|
|
||||||
private getAccountByAddress(address: string) {
|
|
||||||
let account;
|
|
||||||
let index = 0;
|
|
||||||
for (let i = 0, l = this.wallet.length; i < l; i++) {
|
|
||||||
if (this.wallet[i].address === address) {
|
|
||||||
account = this.wallet[i];
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { account, index };
|
|
||||||
}
|
|
||||||
|
|
||||||
public selectAccount(address: string) {
|
|
||||||
const { index } = this.getAccountByAddress(address);
|
|
||||||
if (index !== this.accountIndex && index < this.wallet.length) {
|
|
||||||
this.accountIndex = index;
|
|
||||||
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, this.wallet[index].address);
|
|
||||||
}
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async generateGasShow(gas: any) {
|
public async generateGasShow(gas: any) {
|
||||||
let price = await this.web3.eth.getGasPrice();
|
let price = await this.web3.eth.getGasPrice();
|
||||||
let ehtBN = this.web3.utils.toBN(price).mul(this.web3.utils.toBN(gas));
|
let ehtBN = this.web3.utils.toBN(price).mul(this.web3.utils.toBN(gas));
|
||||||
@ -518,69 +411,6 @@ export default class JCWallet {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateTokenInfo(
|
|
||||||
data: INFT,
|
|
||||||
address: string,
|
|
||||||
index: number,
|
|
||||||
account: string
|
|
||||||
) {
|
|
||||||
const tokenId = await this.wallet.erc721Standard.getCollectibleTokenId(
|
|
||||||
address,
|
|
||||||
account,
|
|
||||||
index
|
|
||||||
);
|
|
||||||
const info = await getJCErc721Info(tokenId);
|
|
||||||
data.tokenId = tokenId;
|
|
||||||
data.name = info.name;
|
|
||||||
data.desc = info.description;
|
|
||||||
data.image = info.image;
|
|
||||||
data.last = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async nftInfo(
|
|
||||||
address: string,
|
|
||||||
index: number,
|
|
||||||
account: string,
|
|
||||||
refresh: boolean
|
|
||||||
) {
|
|
||||||
account = account || this.currentAccAddr;
|
|
||||||
const chain = this.wallet.currentChain.id;
|
|
||||||
const { categor, type } = getTypeByAddress(chain, address);
|
|
||||||
let nfts = [];
|
|
||||||
if (categor !== UNKNOW) {
|
|
||||||
nfts = this.currentAccountData.tokenData[chain][`${categor}s`];
|
|
||||||
}
|
|
||||||
let needRefresh = !(nfts.length > index && nfts[index].tokenId && !refresh);
|
|
||||||
if (needRefresh) {
|
|
||||||
this.updateTokenInfo(nfts[index], address, index, account);
|
|
||||||
saveData(this.data);
|
|
||||||
}
|
|
||||||
return nfts[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
public async nftList(address: string, account?: string) {
|
|
||||||
account = account || this.currentAccAddr;
|
|
||||||
const chain = this.wallet.currentChain.id;
|
|
||||||
const amount = await this.erc721Standard.getBalance(address, account);
|
|
||||||
const { categor, type } = getTypeByAddress(chain, address);
|
|
||||||
let nfts = [];
|
|
||||||
if (categor !== UNKNOW) {
|
|
||||||
nfts = this.currentAccountData.tokenData[chain][`${categor}s`];
|
|
||||||
}
|
|
||||||
let refresh = false;
|
|
||||||
if (nfts.length !== amount) {
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
if (refresh) {
|
|
||||||
nfts.length = 0;
|
|
||||||
for (let i = 0; i < amount; i++) {
|
|
||||||
const nftData = initNFT(address, i, type);
|
|
||||||
nfts.push(nftData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nfts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async sendNFT(
|
public async sendNFT(
|
||||||
address: string,
|
address: string,
|
||||||
to: string,
|
to: string,
|
||||||
@ -636,24 +466,11 @@ export default class JCWallet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFeeAddress(typeName: string) {
|
|
||||||
if (!this.feeAddressMap.has(typeName)) {
|
|
||||||
const address = await this.jcStandard.fetchFeeToAddress(
|
|
||||||
this.currentChain.id,
|
|
||||||
typeName
|
|
||||||
);
|
|
||||||
if (address) {
|
|
||||||
this.feeAddressMap.set(typeName, address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.feeAddressMap.get(typeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async scanQr(title: string) {
|
public async scanQr(title: string) {
|
||||||
let result = (await this.nativeSvr.scanQRCode(title)) + "";
|
let result = (await this.nativeSvr.scanQRCode(title)) + "";
|
||||||
console.log("scan qr code: " + result);
|
console.log("scan qr code: " + result);
|
||||||
if (result && result.indexOf("://") >= 0) {
|
if (result && result.indexOf("://") >= 0) {
|
||||||
await parseUrl(result);
|
parseUrl(result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -663,8 +480,6 @@ export default class JCWallet {
|
|||||||
|
|
||||||
export * from "./common/WalletEvent";
|
export * from "./common/WalletEvent";
|
||||||
export * from "./common/ZError";
|
export * from "./common/ZError";
|
||||||
export * from "./config/chain_config";
|
|
||||||
export * from "./data/DataModel";
|
|
||||||
export * from "./lib/WalletConnect";
|
export * from "./lib/WalletConnect";
|
||||||
export * from "./util/number.util";
|
export * from "./util/number.util";
|
||||||
export * from "./util/wallet.util";
|
export * from "./util/wallet.util";
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { IAccount } from "../data/DataModel";
|
|
||||||
import { aesDecrypt, aesEncrypt } from "../util/crypto.util";
|
import { aesDecrypt, aesEncrypt } from "../util/crypto.util";
|
||||||
import sha256 from "crypto-js/sha256";
|
import sha256 from "crypto-js/sha256";
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ export function saveToken(token: string) {
|
|||||||
|
|
||||||
export function loadData() {
|
export function loadData() {
|
||||||
const dataStr = localStorage.getItem(LOCAL_ACCOUNT_DATAS);
|
const dataStr = localStorage.getItem(LOCAL_ACCOUNT_DATAS);
|
||||||
let result: IAccount[] = [];
|
let result = [];
|
||||||
if (dataStr) {
|
if (dataStr) {
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(dataStr);
|
result = JSON.parse(dataStr);
|
||||||
@ -29,7 +28,7 @@ export function loadData() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveData(datas: IAccount[]) {
|
export function saveData(datas: []) {
|
||||||
const dataStr = JSON.stringify(datas);
|
const dataStr = JSON.stringify(datas);
|
||||||
localStorage.setItem(LOCAL_ACCOUNT_DATAS, dataStr);
|
localStorage.setItem(LOCAL_ACCOUNT_DATAS, dataStr);
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,8 @@ import { abiChipLocker } from "../abis/abiChipLocker";
|
|||||||
import { abiERC1155 } from "../abis/abiERC1155";
|
import { abiERC1155 } from "../abis/abiERC1155";
|
||||||
import { abiEvolveFactory } from "../abis/abiUserEvolveFactory";
|
import { abiEvolveFactory } from "../abis/abiUserEvolveFactory";
|
||||||
import { abiMinterFactory } from "../abis/abiUserMinterFactory";
|
import { abiMinterFactory } from "../abis/abiUserMinterFactory";
|
||||||
import { JC_CONTRACTS } from "../config/chain_config";
|
|
||||||
import { ZERO_ADDRESS } from "../config/constants";
|
import { ZERO_ADDRESS } from "../config/constants";
|
||||||
import { getAddressByType, universalChainCb } from "../util/chain.util";
|
import { getAddressByName, universalChainCb } from "../util/chain.util";
|
||||||
import { SAMPLE_GAS } from "./ChainCommon";
|
import { SAMPLE_GAS } from "./ChainCommon";
|
||||||
|
|
||||||
export class JCStandard {
|
export class JCStandard {
|
||||||
@ -30,7 +29,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].nftMall;
|
let address = jc.wallet.currentChainCfg.contracts.nftMall;
|
||||||
const contract = new this.web3.eth.Contract(abiNftMall, address, {
|
const contract = new this.web3.eth.Contract(abiNftMall, address, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
@ -107,7 +106,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].nftMall;
|
let address = jc.wallet.currentChainCfg.contracts.nftMall;
|
||||||
const contract = new this.web3.eth.Contract(abiNftMall, address, {
|
const contract = new this.web3.eth.Contract(abiNftMall, address, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
@ -189,7 +188,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].evolveFactory;
|
let address = jc.wallet.currentChainCfg.contracts.evolveFactory;
|
||||||
const contract = new this.web3.eth.Contract(abiEvolveFactory, address, {
|
const contract = new this.web3.eth.Contract(abiEvolveFactory, address, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
@ -264,7 +263,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].evolveFactory;
|
let address = jc.wallet.currentChainCfg.contracts.evolveFactory;
|
||||||
const contract = new this.web3.eth.Contract(abiEvolveFactory, address, {
|
const contract = new this.web3.eth.Contract(abiEvolveFactory, address, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
@ -297,7 +296,7 @@ export class JCStandard {
|
|||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
const details = [];
|
const details = [];
|
||||||
const chipAddress = getAddressByType("chip");
|
const chipAddress = getAddressByName("chip");
|
||||||
assert(!!chipAddress, "chip address not found");
|
assert(!!chipAddress, "chip address not found");
|
||||||
// chip evolved
|
// chip evolved
|
||||||
details.push({
|
details.push({
|
||||||
@ -348,7 +347,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].minterFactory;
|
let address = jc.wallet.currentChainCfg.contracts.minterFactory;
|
||||||
const contract = new this.web3.eth.Contract(abiMinterFactory, address, {
|
const contract = new this.web3.eth.Contract(abiMinterFactory, address, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
@ -381,7 +380,7 @@ export class JCStandard {
|
|||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
const details = [];
|
const details = [];
|
||||||
const shardAddress = getAddressByType("shard");
|
const shardAddress = getAddressByName("shard");
|
||||||
assert(!!shardAddress, "shard address not found");
|
assert(!!shardAddress, "shard address not found");
|
||||||
// shard
|
// shard
|
||||||
for (let i = 0, l = tokenIds.length; i < l; i++) {
|
for (let i = 0, l = tokenIds.length; i < l; i++) {
|
||||||
@ -432,7 +431,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].minterFactory;
|
let address = jc.wallet.currentChainCfg.contracts.minterFactory;
|
||||||
const contract = new this.web3.eth.Contract(abiMinterFactory, address, {
|
const contract = new this.web3.eth.Contract(abiMinterFactory, address, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
@ -476,11 +475,11 @@ export class JCStandard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const details = [];
|
const details = [];
|
||||||
const shardAddress = getAddressByType("shard");
|
const shardAddress = getAddressByName("shard");
|
||||||
assert(!!shardAddress, "shard address not found");
|
assert(!!shardAddress, "shard address not found");
|
||||||
// nft mint
|
// nft mint
|
||||||
const nftTypeName = nftType === 0 ? "hero" : "weapon";
|
const nftTypeName = nftType === 0 ? "hero" : "weapon";
|
||||||
const nftAddress = getAddressByType(nftTypeName);
|
const nftAddress = getAddressByName(nftTypeName);
|
||||||
assert(!!nftAddress, "nft address not found");
|
assert(!!nftAddress, "nft address not found");
|
||||||
details.push({
|
details.push({
|
||||||
address: nftAddress,
|
address: nftAddress,
|
||||||
@ -548,8 +547,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let lockerAddress =
|
let lockerAddress = jc.wallet.currentChainCfg.contracts.chipLocker;
|
||||||
JC_CONTRACTS[window.jc.wallet.currentChain.id].chipLocker;
|
|
||||||
const contract = new this.web3.eth.Contract(abiChipLocker, lockerAddress, {
|
const contract = new this.web3.eth.Contract(abiChipLocker, lockerAddress, {
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
});
|
});
|
||||||
@ -657,7 +655,7 @@ export class JCStandard {
|
|||||||
gas?: number;
|
gas?: number;
|
||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
let lockerAddress = JC_CONTRACTS[jc.wallet.currentChain.id].chipLocker;
|
let lockerAddress = jc.wallet.currentChainCfg.contracts.chipLocker;
|
||||||
const contract = new this.web3.eth.Contract(abiChipLocker, lockerAddress, {
|
const contract = new this.web3.eth.Contract(abiChipLocker, lockerAddress, {
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
});
|
});
|
||||||
@ -718,13 +716,4 @@ export class JCStandard {
|
|||||||
.send({ gas })
|
.send({ gas })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch feeToAddress from contact
|
|
||||||
async fetchFeeToAddress(chain: number, typeName: string) {
|
|
||||||
// jc.wallet.currentChain.id
|
|
||||||
let address = JC_CONTRACTS[chain][typeName];
|
|
||||||
assert(address, "address not found");
|
|
||||||
const contract = new this.web3.eth.Contract(abiChipLocker, address);
|
|
||||||
return contract.methods.feeToAddress().call();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { BASE_TOKEN_URI, DEFAULT_NFT_TYPES } from "../config/chain_config";
|
import { BASE_TOKEN_URI, TX_CONFIRM_BLOCKS } from "../config/constants";
|
||||||
import { TX_CONFIRM_BLOCKS } from "../config/constants";
|
|
||||||
import { LoggerQueue } from "../queue/record.queue";
|
import { LoggerQueue } from "../queue/record.queue";
|
||||||
import { toBN } from "web3-utils";
|
import { toBN } from "web3-utils";
|
||||||
|
|
||||||
@ -54,27 +53,28 @@ export function toHexChainId(chainId: number) {
|
|||||||
return "0x" + chainId.toString(16);
|
return "0x" + chainId.toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTypeByAddress(chain: number, address: string) {
|
export function getTypeByAddress(address: string) {
|
||||||
const cfgs = DEFAULT_NFT_TYPES[chain];
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
let categor = UNKNOW;
|
let type = "erc721";
|
||||||
let type: "erc721" | "erc1155" = "erc721";
|
if (cfg && cfg.tokens) {
|
||||||
if (cfgs) {
|
for (let token of cfg.tokens) {
|
||||||
for (let key in cfgs) {
|
if (token.address.toLowerCase() === address.toLowerCase()) {
|
||||||
if (cfgs[key] && cfgs[key].address === address) {
|
type = token.type;
|
||||||
categor = key;
|
|
||||||
type = cfgs[key].type;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { categor, type };
|
return { type };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAddressByType(typeName: string) {
|
export function getAddressByName(typeName: string) {
|
||||||
const cfgs = DEFAULT_NFT_TYPES[jc.wallet.currentChain.id];
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
let address = "";
|
let address = "";
|
||||||
if (cfgs) {
|
if (cfg && cfg.tokens) {
|
||||||
if (cfgs[typeName]) {
|
let result = cfg.tokens.find(
|
||||||
address = cfgs[typeName].address;
|
(token) => token.name === typeName || token.symbol === typeName
|
||||||
|
);
|
||||||
|
if (result) {
|
||||||
|
address = result.address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user