Skip to content

Commit

Permalink
put the nextMeetupTime function in MapSidebar (#111)
Browse files Browse the repository at this point in the history
* put the next meetup time function in the mapSidebar

* solved the errors that I got

* had to solve more errors

* Put the next ceremony date in a more presentable place

* [MapSidebar] made the Time when the Ceremony starts visible

* [MapSidebar] console.log is in the getNextMeetupDate function

* [MapSidebar] Put the timezone in the getNextMeetupDate function

* committing the mapbox module

* let's see if this fixes the problem

* testing if putting it in package.json will solve the problem

* This should solve the problem that we had

* fix timezone for meetup time

* cleanup

---------

Co-authored-by: brenzi <brenzi@users.noreply.github.com>
Co-authored-by: Alain Brenzikofer <alain@integritee.network>
  • Loading branch information
3 people authored Mar 15, 2023
1 parent 31687eb commit f559e63
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 14 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.8",
"@mapbox/tilebelt": "^1.0.2",
"@mapbox/timespace": "^2.0.4",
"eslint": "^8.6.0",
"eslint-config-semistandard": "^16.0.0",
"eslint-config-standard": "^16.0.3",
Expand Down
20 changes: 18 additions & 2 deletions src/map/MapSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import Big from 'big.js';
import toFormat from 'toformat';
import { parseEncointerBalance } from '@encointer/types';

import { getCeremonyIncome } from '@encointer/node-api';
import { getCeremonyIncome, getNextMeetupTime } from '@encointer/node-api';
import { parseI64F64 } from '@encointer/util';
import { ipfsCidFromHex } from '../utils';
import { ipfsCidFromHex, locationFromJson } from '../utils';
import timespace from '@mapbox/timespace';

const BigFormat = toFormat(Big);

Expand Down Expand Up @@ -310,6 +311,20 @@ function MapSidebarMain (props) {
}
}, [api, cid, participantCount]);

const [nextMeetupTime, setNextMeetupTime] = useState([]);
// gets the date of the next Meetup
useEffect(() => {
async function getNextMeetupDate () {
const meetupLocations = await api.rpc.encointer.getLocations(cid);
const referenceLocation = locationFromJson(api, meetupLocations[0]);
const meetupTimeUtc = await getNextMeetupTime(api, referenceLocation);

const localTime = timespace.getFuzzyLocalTimeFromPoint(meetupTimeUtc.toNumber(), [meetupLocations[0].lon, meetupLocations[0].lat]);
setNextMeetupTime(localTime.toString());
}
getNextMeetupDate();
}, [api, cid, debug]);

return (
<Sidebar
className='details-sidebar'
Expand All @@ -334,6 +349,7 @@ function MapSidebarMain (props) {
<Header sub textAlign='left'>Currency ID:</Header>
<Message size='small' color='blue'>{hash}</Message>
<p>{name}</p>
<div>Next ceremony: {nextMeetupTime}</div>
</Segment>

<Segment.Group textalign='left'>
Expand Down
15 changes: 3 additions & 12 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { bnToU8a } from '@polkadot/util';
import { stringToDegree } from '@encointer/types';

function mapReduce (arr, mapperFn, reducerFn) {
Expand Down Expand Up @@ -32,21 +31,13 @@ export function ipfsCidFromHex (ipfsCidHex) {
/**
* Parses a location json with fields as number strings to a `Location` object.
*
* There is a rust vs. JS endian issue with numbers: https://github.com/polkadot-js/api/issues/4313.
*
* tl;dr: If the returned location is processed:
* * by a node (rust), use isLe = false.
* * by JS, e.g. `parseDegree`, use isLe = true.
*
*
* @param api
* @param location fields as strings, e.g. '35.2313515312'
* @param isLe
* @returns {Location} Location with fields as fixed-point numbers
*/
export function locationFromJson (api, location, isLe = true) {
export function locationFromJson (api, location) {
return api.createType('Location', {
lat: bnToU8a(stringToDegree(location.lat), 128, isLe),
lon: bnToU8a(stringToDegree(location.lon), 128, isLe)
lat: stringToDegree(location.lat),
lon: stringToDegree(location.lon)
});
}
106 changes: 106 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// const path = require("path");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");

module.exports = {
mode: "development",
target: "web",
entry: ["regenerator-runtime/runtime", "./src/index.js"],
output: {
filename: "bundle.js",
path: path.join(__dirname, "dist"),
publicPath: "/",
},
resolve: {
extensions: [".js", ".css"],
alias: {
// add as many aliases as you like!
components: path.resolve(__dirname, "src/components"),
},

//****************** INSTEAD OF MANUALLY INSTALLING YOU CAN USE NodePolyfillPlugin */

// fallback: {
// // path: require.resolve("path-browserify"),
// fs: false,
// assert: require.resolve("assert/"),
// os: require.resolve("os-browserify/browser"),
// constants: require.resolve("constants-browserify"),
// stream: require.resolve("stream-browserify"),
// crypto: require.resolve("crypto-browserify"),
// http: require.resolve("stream-http"),
// https: require.resolve("https-browserify"),
// },
},
// devtool: "eval-cheap-source-map",
devtool: "eval",
module: {
rules: [
{ test: /\.(js|jsx)/, loader: "babel-loader", exclude: /node_modules/ },
{ test: /\.css$/, use: ["style-loader", "css-loader"] },
// {
// test: /\.m?js/,
// resolve: {
// fullySpecified: false
// }
// },
{
test: /\.(woff(2)?|ttf|eot|jpg|jpeg|png|gif)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[contenthash].[ext]",
outputPath: "fonts/",
},
},
],
},
{
test: /\.svg$/,
use: [
{
loader: "svg-url-loader",
options: {
limit: 10000,
},
},
],
},
{
test: /\.json5$/i,
loader: "json5-loader",
type: "javascript/auto",
options: {
esModule: true,
},
},
],
},
devServer: {
contentBase: path.join(__dirname, "build"),
historyApiFallback: true,
overlay: true,
},

plugins: [
new HtmlWebpackPlugin({
title: "esBUild",
template: "src/index.html",
}),
new NodePolyfillPlugin(),
// new CopyWebpackPlugin({
// patterns: [{ from: "assets", to: "assets" }],
// }),

// *****************IF YOU ARE NOT USING NodePolyfillPlugin YOU HAVE TO ADD THIS ****************
// new webpack.ProvidePlugin({
// process: "process/browser",
// Buffer: ["buffer", "Buffer"],
// React: "react",
// }),
],
};
110 changes: 110 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,39 @@ __metadata:
languageName: node
linkType: hard

"@mapbox/tile-cover@npm:^3.0.2":
version: 3.0.2
resolution: "@mapbox/tile-cover@npm:3.0.2"
dependencies:
"@mapbox/tilebelt": ^1.0.1
checksum: 22ee9ddac5da1781a354bf43e4e7e95f43b8bad9595c86698ffa6634cf8d3b09bdca321ae0c2008b3b14412770c0681f27ff00cc7e4a7fa09408b26e75d76ee4
languageName: node
linkType: hard

"@mapbox/tilebelt@npm:^1.0.1, @mapbox/tilebelt@npm:^1.0.2":
version: 1.0.2
resolution: "@mapbox/tilebelt@npm:1.0.2"
checksum: 923bdcd93f4db4ef9cee64c622fc1852f4da461af0fb14864083e791192a84ce9d5b8e237db1cc71944c63ed3d0121f8e9da2b28c46e0d61bcbe1f99ebbde6f7
languageName: node
linkType: hard

"@mapbox/timespace@npm:^2.0.4":
version: 2.0.4
resolution: "@mapbox/timespace@npm:2.0.4"
dependencies:
"@mapbox/tile-cover": ^3.0.2
"@mapbox/tilebelt": ^1.0.1
d3-queue: ^3.0.3
mkdirp: ^0.5.1
moment: ^2.12.0
moment-timezone: ^0.5.5
rimraf: ^2.5.4
simple-statistics: ^2.3.0
tile-cover: ^3.0.1
checksum: 4d1f3ea3745c66f28af5ab58448bf8feeece4c23b2be3815ba4d3b98d1d3a77b2d9964fa52dd324c30a586a5eab98dd923d49586e7c0964bcf1e097fb0bf7b1d
languageName: node
linkType: hard

"@noble/hashes@npm:0.5.7":
version: 0.5.7
resolution: "@noble/hashes@npm:0.5.7"
Expand Down Expand Up @@ -6354,6 +6387,13 @@ __metadata:
languageName: node
linkType: hard

"d3-queue@npm:^3.0.3":
version: 3.0.7
resolution: "d3-queue@npm:3.0.7"
checksum: 04d084dc0f031af29c7378f70c0a650f11d5880efa05ffda509d1c88332b0c63b41ce36226e74a59554f64fcc59b171d21023670972ac5ab23cbc36d475ae8c6
languageName: node
linkType: hard

"d@npm:1, d@npm:^1.0.1":
version: 1.0.1
resolution: "d@npm:1.0.1"
Expand Down Expand Up @@ -7873,6 +7913,8 @@ __metadata:
"@encointer/types": ^0.8.6
"@encointer/util": ^0.8.6
"@encointer/worker-api": ^0.8.6
"@mapbox/tilebelt": ^1.0.2
"@mapbox/timespace": ^2.0.4
"@polkadot/api": ^7.3.1
"@polkadot/extension-dapp": ^0.42.5
"@polkadot/keyring": ^8.3.1
Expand Down Expand Up @@ -10864,6 +10906,13 @@ __metadata:
languageName: node
linkType: hard

"minimist@npm:^1.2.6":
version: 1.2.7
resolution: "minimist@npm:1.2.7"
checksum: 7346574a1038ca23c32e02252f603801f09384dd1d78b69a943a4e8c2c28730b80e96193882d3d3b22a063445f460e48316b29b8a25addca2d7e5e8f75478bec
languageName: node
linkType: hard

"minipass-collect@npm:^1.0.2":
version: 1.0.2
resolution: "minipass-collect@npm:1.0.2"
Expand Down Expand Up @@ -10941,6 +10990,17 @@ __metadata:
languageName: node
linkType: hard

"mkdirp@npm:^0.5.1":
version: 0.5.6
resolution: "mkdirp@npm:0.5.6"
dependencies:
minimist: ^1.2.6
bin:
mkdirp: bin/cmd.js
checksum: 0c91b721bb12c3f9af4b77ebf73604baf350e64d80df91754dc509491ae93bf238581e59c7188360cec7cb62fc4100959245a42cfe01834efedc5e9d068376c2
languageName: node
linkType: hard

"mkdirp@npm:^0.5.5, mkdirp@npm:~0.5.1":
version: 0.5.5
resolution: "mkdirp@npm:0.5.5"
Expand Down Expand Up @@ -10975,6 +11035,22 @@ __metadata:
languageName: node
linkType: hard

"moment-timezone@npm:^0.5.5":
version: 0.5.40
resolution: "moment-timezone@npm:0.5.40"
dependencies:
moment: ">= 2.9.0"
checksum: 6f6be5412b37fd937bb143efe74bf65b2c3f115fd967a6dc13b717a126ed6dd198bff6db6e179d69a089e20ac03ce7622c6b5598dd585005195554487a91b528
languageName: node
linkType: hard

"moment@npm:>= 2.9.0, moment@npm:^2.12.0":
version: 2.29.4
resolution: "moment@npm:2.29.4"
checksum: 0ec3f9c2bcba38dc2451b1daed5daded747f17610b92427bebe1d08d48d8b7bdd8d9197500b072d14e326dd0ccf3e326b9e3d07c5895d3d49e39b6803b76e80e
languageName: node
linkType: hard

"ms@npm:2.0.0":
version: 2.0.0
resolution: "ms@npm:2.0.0"
Expand Down Expand Up @@ -13616,6 +13692,17 @@ __metadata:
languageName: node
linkType: hard

"rimraf@npm:^2.5.4":
version: 2.7.1
resolution: "rimraf@npm:2.7.1"
dependencies:
glob: ^7.1.3
bin:
rimraf: ./bin.js
checksum: cdc7f6eacb17927f2a075117a823e1c5951792c6498ebcce81ca8203454a811d4cf8900314154d3259bb8f0b42ab17f67396a8694a54cae3283326e57ad250cd
languageName: node
linkType: hard

"rimraf@npm:^3.0.0, rimraf@npm:^3.0.2":
version: 3.0.2
resolution: "rimraf@npm:3.0.2"
Expand Down Expand Up @@ -14110,6 +14197,13 @@ __metadata:
languageName: node
linkType: hard

"simple-statistics@npm:^2.3.0":
version: 2.5.0
resolution: "simple-statistics@npm:2.5.0"
checksum: fa6c614d87c650ce5668af598cffda8c33f28423a53a3a98c12abd87d0d92b8887b1009055fd1376a82b86dc37b4a7e02d27224b9cc0eca7ba12ad1bf3310b81
languageName: node
linkType: hard

"sisteransi@npm:^1.0.5":
version: 1.0.5
resolution: "sisteransi@npm:1.0.5"
Expand Down Expand Up @@ -14974,6 +15068,22 @@ __metadata:
languageName: node
linkType: hard

"tile-cover@npm:^3.0.1":
version: 3.0.1
resolution: "tile-cover@npm:3.0.1"
dependencies:
tilebelt: ^1.0.1
checksum: 2ffbba233d1f568c6cd64cd6eea7f676185fbd9c64e56708ecbe4ea05483ff9ac5c736389229c8017a70c40658fb63904a7157d393b24fa1fd041290379d5e26
languageName: node
linkType: hard

"tilebelt@npm:^1.0.1":
version: 1.0.1
resolution: "tilebelt@npm:1.0.1"
checksum: f201cf1718f53b8d7b2e89f53f90bbcf6eba5f58fe578da5ce35f93ea4e2302100f019fe2d388a0fb7ec5ceda0b6a0f08d10657b6b54eb5d74db218ad4bad177
languageName: node
linkType: hard

"timsort@npm:^0.3.0":
version: 0.3.0
resolution: "timsort@npm:0.3.0"
Expand Down

0 comments on commit f559e63

Please sign in to comment.