Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Testing merge to master branch (#8)
Browse files Browse the repository at this point in the history
* feat: migrate to web3 v1.0

* chore: lots of boring api-breaking-changing stuff

* fix: fix buyItem error

* feat: fill sth for luckydraw

* 首页 收藏页 静态

* no message

* 除了排行榜

* feat: enable circle-ci

* Introduce Circle CI for build testing (#7)

* fix: ci config file

* rm: some deprecated package and try to fix yarn install error

* rm: remove useless static files
  • Loading branch information
frankwei98 authored May 26, 2018
1 parent d97ceb6 commit fef142a
Show file tree
Hide file tree
Showing 271 changed files with 2,623 additions and 254 deletions.
41 changes: 41 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:8.11.1

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
- checkout
# Download and cache dependencies
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-{{ .Branch }}
- yarn-packages-master
- yarn-packages-

- run:
name: Install Dependencies
command: yarn install

- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules/

# run builds!
- run: yarn run build
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, shrink-to-fit=no">
<link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" />
<title>币娘 Collection</title>
<link href="https://cdn.bootcss.com/bulma/0.6.2/css/bulma.min.css" rel="stylesheet">
Expand Down
34 changes: 0 additions & 34 deletions k8s/deployment.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"bignumber.js": "^6.0.0",
"bluebird": "^3.5.1",
"buefy": "^0.6.5",
"dravatar": "^1.0.2",
"ethereum-blockies-png": "^0.1.2",
"js-cookie": "^2.2.0",
Expand All @@ -26,10 +26,11 @@
"vue-config": "^1.0.0",
"vue-i18n": "^7.4.2",
"vue-lazyload": "^1.2.1",
"vue-resource": "^1.5.1",
"vue-router": "^3.0.1",
"vue-spinner": "^1.0.3",
"vuex": "^3.0.1",
"web3": "0.20.4"
"web3": "^1.0.0-beta.34"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
Expand Down
9 changes: 8 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="app">
<Header />

<div class="container main-container">
<div>
<router-view :key="key"></router-view>
</div>

Expand All @@ -13,13 +13,20 @@
<script>
import Header from '@/components/Header';
import Footer from '@/components/Footer';
import { mapActions } from 'vuex';
export default {
name: 'App',
components: {
Header,
Footer,
},
async created() {
await this.setContract();
},
methods: {
...mapActions(['setContract']),
},
computed: {
key() {
return this.$route.name !== undefined
Expand Down
154 changes: 85 additions & 69 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Promise from 'bluebird';
// import Promise from 'bluebird';
import Cookie from 'js-cookie';
import { BigNumber } from 'bignumber.js';
import web3 from '@/web3';
import * as config from '@/config';
import request from 'superagent';
import timeout from 'timeout-then';
import cryptoWaterMarginABI from './abi/cryptoWaterMargin.json';
import convertContractABI from './abi/convertContract.json';
// import cryptoWaterMarginABI from './abi/cryptoWaterMargin.json';
// import convertContractABI from './abi/convertContract.json';

// Sometimes, web3.version.network might be undefined,
// as a workaround, use defaultNetwork in that case.
const network = config.network[web3.version.network] || config.defaultNetwork;
const cryptoWaterMarginContract = web3.eth.contract(cryptoWaterMarginABI).at(network.contract);
// const network = config.network[web3.version.network] || config.defaultNetwork;
// const cryptoWaterMarginContract = web3.eth.contract(cryptoWaterMarginABI).at(network.contract);

// This contract supposed to convert CWM to Lucky
const convertContract = web3.eth.contract(convertContractABI).at(network.convert);
// // This contract supposed to convert CWM to Lucky
// const convertContract = web3.eth.contract(convertContractABI).at(network.convert);

let store = [];
let isInit = false;
Expand Down Expand Up @@ -158,7 +158,8 @@ export const getNextPrice = async (id, time = 0) => {
// price为用户成功发起交易的交易价格,调用setNextPrice后,nextPrice会变为此价格的1.1倍
export const setNextPrice = async (id, priceInWei) => {
// Convert price(Wei) to a number instance (ether)
const price = Number(web3.fromWei(priceInWei, 'ether').toString());
// const price = Number(web3.utils.fromWei(priceInWei, 'ether').toString());
const price = web3.utils.fromWei(priceInWei, 'ether');
const response = await request
.get('https://api.leancloud.cn/1.1/classes/ad')
.set({
Expand Down Expand Up @@ -212,57 +213,57 @@ export const setNextPrice = async (id, priceInWei) => {
return price * 1.1;
};

export const getItem = async (id) => {
const exist = await Promise.promisify(cryptoWaterMarginContract.tokenExists)(id);
if (!exist) return null;
const card = config.cards[id] || {};
const item = {
id,
name: card.name,
nickname: card.nickname,
};
[item.owner, item.price, item.nextPrice] =
await Promise.promisify(cryptoWaterMarginContract.allOf)(id);

// [[item.owner, item.price, item.nextPrice], item.estPrice] = await Promise.all([
// Promise.promisify(cryptoWaterMarginContract.allOf)(id),
// getNextPrice(id)]);
// item.price = BigNumber.maximum(item.price, item.estPrice);
return item;
};

export const buyItem = (id, price) => new Promise((resolve, reject) => {
cryptoWaterMarginContract.buy(id, {
value: price, // web3.toWei(Number(price), 'ether'),
gas: 220000,
gasPrice: 1000000000 * 100,
},
(err, result) => (err ? reject(err) : resolve(result)));
});

// Lucky Part
export const exchangeLuckyToken = tokenId => new Promise((resolve, reject) => {
convertContract.getNewToken(tokenId, {
value: 0, // web3.toWei(Number(price), 'ether'),
gas: 80000,
gasPrice: 1000000000 * 18,
},
(err, result) => (err ? reject(err) : resolve(result)));
});

export const isConvert = cardId => new Promise((resolve, reject) => {
convertContract.isConvert(cardId,
(err, result) => (err ? reject(err) : resolve(result)));
});

export const getTotal = () => Promise.promisify(cryptoWaterMarginContract.totalSupply)();

export const getItemIds = async (offset, limit) => {
let ids = await Promise.promisify(cryptoWaterMarginContract.itemsForSaleLimit)(offset, limit);
ids = ids.map(id => id.toNumber());
ids.sort((a, b) => a - b);
return Array.from(new Set(ids));
};
// export const getItem = async (id) => {
// const exist = await Promise.promisify(cryptoWaterMarginContract.tokenExists)(id);
// if (!exist) return null;
// const card = config.cards[id] || {};
// const item = {
// id,
// name: card.name,
// nickname: card.nickname,
// };
// [item.owner, item.price, item.nextPrice] =
// await Promise.promisify(cryptoWaterMarginContract.allOf)(id);

// // [[item.owner, item.price, item.nextPrice], item.estPrice] = await Promise.all([
// // Promise.promisify(cryptoWaterMarginContract.allOf)(id),
// // getNextPrice(id)]);
// // item.price = BigNumber.maximum(item.price, item.estPrice);
// return item;
// };

// export const buyItem = (id, price) => new Promise((resolve, reject) => {
// cryptoWaterMarginContract.buy(id, {
// value: price, // web3.toWei(Number(price), 'ether'),
// gas: 220000,
// gasPrice: 1000000000 * 100,
// },
// (err, result) => (err ? reject(err) : resolve(result)));
// });

// // Lucky Part
// export const exchangeLuckyToken = tokenId => new Promise((resolve, reject) => {
// convertContract.getNewToken(tokenId, {
// value: 0, // web3.toWei(Number(price), 'ether'),
// gas: 80000,
// gasPrice: 1000000000 * 18,
// },
// (err, result) => (err ? reject(err) : resolve(result)));
// });

// export const isConvert = cardId => new Promise((resolve, reject) => {
// convertContract.isConvert(cardId,
// (err, result) => (err ? reject(err) : resolve(result)));
// });

// export const getTotal = () => Promise.promisify(cryptoWaterMarginContract.totalSupply)();

// export const getItemIds = async (offset, limit) => {
// let ids = await Promise.promisify(cryptoWaterMarginContract.itemsForSaleLimit)(offset, limit);
// ids = ids.map(id => id.toNumber());
// ids.sort((a, b) => a - b);
// return Array.from(new Set(ids));
// };

export const isItemMaster = async (id) => {
const me = await getMe();
Expand All @@ -271,20 +272,35 @@ export const isItemMaster = async (id) => {
return me && me.address && item && item.owner && me.address === item.owner;
};

export const getItemsOf = async (address) => {
let ids = await Promise.promisify(
cryptoWaterMarginContract.tokensOf)(address)
;
ids = ids.map(id => id.toNumber());
ids.sort((a, b) => a - b);
return Array.from(new Set(ids));
};

// export const getItemsOf = async (address) => {
// let ids = await Promise.promisify(
// cryptoWaterMarginContract.tokensOf)(address)
// ;
// ids = ids.map(id => id.toNumber());
// ids.sort((a, b) => a - b);
// return Array.from(new Set(ids));
// };

// export const getNetwork = async () => {
// const netId = await Promise.promisify(web3.version.getNetwork)();
// return config.network[netId];
// };
const promisify = func => new Promise((resolve, reject) => {
func((err, data) => {
if (data) {
return resolve(data);
}
return reject(err);
});
});
// New API
export const getNetwork = async () => {
const netId = await Promise.promisify(web3.version.getNetwork)();
// const getId = () =>
const netId = await promisify(web3.eth.net.getId);
return config.network[netId];
};


export const getLocale = async () => (
Cookie.get('locale') ||
(
Expand Down
Binary file added src/assets/collection_bk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/home_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/home_girls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/home_girls_bk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/usericon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fef142a

Please sign in to comment.