Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Merge branch 'v1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederic committed Jan 28, 2019
2 parents 9def608 + a357e40 commit b97272a
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 136 deletions.
38 changes: 26 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ jobs:
name: Building eWallet in production environment
command: |
set -xe
mix deps.clean mime --build
make build-prod
- run:
name: Building eWallet Docker image
Expand Down Expand Up @@ -282,21 +283,28 @@ jobs:
sh docker-gen.sh -i "$IMAGE_NAME" -n net0 -f .env > docker-compose.override.yml
docker-compose up -d postgres mail
docker-compose run --rm ewallet bin/ewallet initdb
docker-compose run --rm ewallet bin/ewallet seed -e
docker-compose run --rm ewallet bin/ewallet config base_url http://ewallet:4000
docker-compose run --rm ewallet bin/ewallet config email_adapter smtp
docker-compose run --rm ewallet bin/ewallet config smtp_host mail
docker-compose run --rm ewallet bin/ewallet config smtp_port 1025
docker-compose run --rm ewallet sh \<<EOF
bin/ewallet initdb
bin/ewallet seed -e
bin/ewallet config base_url http://ewallet:4000
bin/ewallet config email_adapter smtp
bin/ewallet config smtp_host mail
bin/ewallet config smtp_port 1025
EOF
- run:
name: Configure E2E secret
command: |
docker-compose run --rm ewallet bin/ewallet config aws_bucket $AWS_BUCKET > /dev/null
docker-compose run --rm ewallet bin/ewallet config aws_region $AWS_REGION > /dev/null
docker-compose run --rm ewallet bin/ewallet config aws_access_key_id $AWS_ACCESS_KEY_ID > /dev/null
docker-compose run --rm ewallet bin/ewallet config aws_secret_access_key $AWS_SECRET_ACCESS_KEY > /dev/null
docker-compose run --rm ewallet bin/ewallet config gcs_bucket $GCS_BUCKET > /dev/null
docker-compose run --rm ewallet bin/ewallet config gcs_credentials $GCS_CREDENTIALS > /dev/null
docker-compose run --rm ewallet sh \<<EOF >/dev/null 2>&1
bin/ewallet config aws_bucket "$AWS_BUCKET"
bin/ewallet config aws_region "$AWS_REGION"
bin/ewallet config aws_access_key_id "$AWS_ACCESS_KEY_ID"
bin/ewallet config aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
bin/ewallet config gcs_bucket "$GCS_BUCKET"
EOF
# Use printf/awk to unescape the string with double escaping.
unescaped_gcs_creds="$(printf "%b" "$GCS_CREDENTIALS" | awk '{ gsub("\\\\\"", "\""); print $0 }')"
docker-compose run --rm ewallet config gcs_credentials "$unescaped_gcs_creds" >/dev/null 2>&1
- run:
name: Running E2E tests
command: |
Expand Down Expand Up @@ -393,6 +401,10 @@ workflows:
branches:
ignore:
- master
- /^v.*/
- /\-e2e$/
tags:
ignore: /^v.*/

# Mainline branches only
- build:
Expand All @@ -403,6 +415,8 @@ workflows:
branches:
only:
- master
- /^v.*/
- /\-e2e$/
tags:
only: /^v.*/
- test_e2e:
Expand Down
82 changes: 1 addition & 81 deletions apps/admin_panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,4 @@
The OmiseGO Wallet admin panel for a provider to manage staff, users, roles and permissions,
API access, tokens, transactions, etc.

## Usage

### Development

You will first need to create the `.env` file located under the project's root directory
with your own keys. `ADMIN_API_BASE_URL` is your Admin API server url. `ADMIN_API_KEY_ID` and
`ADMIN_API_KEY` are the access keys corresponding to your Admin API.

Example **.env** file
```
ADMIN_PANEL_BASE_DIR=YOUR_ADMIN_PANEL_BASE_DIR
ADMIN_API_BASE_URL=YOUR_ADMIN_API_BASE_URL
ADMIN_API_KEY_ID=YOUR_API_KEY_ID
ADMIN_API_KEY=YOUR_API_KEY
```

### Running the Admin Panel

The Admin Panel will be started along with the whole umbrella app.
There are no extra steps required to start the Admin Panel.

### Tests

Run tests using the command below.

```shell
yarn test
```

or if you want to run tests on every file change:

```shell
yarn test:watch
```

## Development

### Front End Build Pipeline

The build pipeline can be broken down into 2 major steps: 1) **[Yarn](https://yarnpkg.com)**
installs the project's dependencies, 2) **[Webpack](https://webpack.js.org)** then orchestrates
other packages and plugins to do the build for it. It then bundles up the built files together,
and ready them to be served to the client.

To add a new step to the build pipeline, the easiest to do is to find a webpack loader/plugin
that does the job, then add it to the current webpack pipeline (in `config/webpack.js`).

**Note:** The purpose of this section is to illustrate the major steps that source files go through
until being served to the client, not to detail each and every build steps performed. There may be
other tools used in between the pipeline steps that are not mentioned here.

1. **Yarn**: Install dependencies and manage yarn command aliases
2. **Webpack**: Bundle assets together into small packages to optimize load time.
1. **babel-loader**: Use Babel to compile modern JavaScript down for compatibility
with older browsers
2. **uglifyjs-webpack-plugin**: Minify JavaScript files for efficiency
3. **html-webpack-plugin**: Generate the html that serves the built files
4. **webpack-dev-server**: Serve the files to the browser. Its trick is it monitors source file
changes, rebuilds them, then automatically refreshes the browser with the built files.

### Front-End Directory Structure

```text
assets/
├─ __tests__/ Test files.
├─ config/ The folder for storing app and library configs
├─ node_modules/ **Autogenerated. Do not edit.** Node dependencies
├─ public/ Asset files that do not need to be processed. Your images, icons, fonts,
│ videos and other static files should go here.
├─ src/ Source files that need to be processed. Your JS, JSX, EJS files
│ should go here.
├─ stories/ Source files for the stories.
├─ .gitignore The list of files and folders that git should ignore
├─ package.json The manifest that contains project's metadata, dependencies, etc.
├─ README.md The document you are currently reading explaining how to get started
├─ yarn.lock **Autogenerated. Do not edit.** Yarn lockfile
└─ .babelrc The babelrc config file
```

Jumping onto the project? Get started by reading `assets/package.json`, `assets/config/webpack.js`,
then jump onto `assets/src/index.js`, the JS entrypoint of the project.
To start the Admin Panel in development mode, follow these [instructions](./assets/README.md)
32 changes: 30 additions & 2 deletions apps/admin_panel/assets/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# admin-panel-v2
A admin panel for e-wallet.
# Admin Panel

The OmiseGO Wallet admin panel for a provider to manage staff, users, roles and permissions,
API access, tokens, transactions, etc.

## Usage

Running the Admin Panel in development mode locally allows you to modify the code and see changes in real-time. You may connect to any eWallet as a backend, which can be running locally or remotely which will depend on your config file.

### Development

1. You will first need to create the `.env` file located under the project's root directory `/apps/admin_panel/assets/` of the app with your own keys. There are 2 keys that is needed to be able to run and connect to the server `BACKEND_API_URL` and `BACKEND_WEBSOCKET_URL`

Example **.env** file
```
BACKEND_API_URL=https://omisego.network/admin/api
BACKEND_WEBSOCKET_URL=https://omisego.network/admin/socket
```

2. Install dependencies with `yarn install` if you don't have yarn please install it first https://yarnpkg.com/lang/en/docs/install/
3. Start the development server `yarn start` and go to `http://localhost:9000` and test it out.

_That's all, now you are ready to customize the admin panel as your own need._

### Production
To build the production app, use `yarn build` this will build a production version of admin panel and output in `/apps/admin_panel/priv/static` for the phoenix application to serve. **Note that the output path is the root of the eWallet app not the admin panel**

### Testing
For unit test, just run `yarn test` and for linting run `yarn lint`

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function updateConfiguration ({
balance_caching_strategy: balanceCachingStrategy,
forget_password_request_lifetime: Number(forgetPasswordRequestLifetime)
},
value => _.isNil(value) || _.isNaN(value) || 0 || ''
value => _.isNil(value) || _.isNaN(value) || value === 0
)
return authenticatedRequest({
path: '/configuration.update',
Expand Down
41 changes: 23 additions & 18 deletions apps/admin_panel/assets/src/services/configurationService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ import { updateConfiguration } from './configurationService'
import * as apiService from '../services/apiService'
jest.mock('./apiService.js')
describe('configurationService', () => {
test('it should omit null, undefined, Nan, 0, "" value out before sending', () => {})
apiService.authenticatedRequest.mockImplementation(() => {
return Promise.resolve({
data: {
success: true
}
test('it should omit null, undefined, Nan, 0, "" value out before sending', () => {
apiService.authenticatedRequest.mockImplementation(() => {
return Promise.resolve({
data: {
success: true
}
})
})
})
updateConfiguration({
baseUrl: 'url',
redirectUrlPrefixes: [],
maxPerPage: null,
minPasswordLength: undefined,
senderEmail: NaN,
smtpUsername: ''
}).then(() => {
expect(apiService.authenticatedRequest).toBeCalledWith({
path: '/configuration.update',
data: { baseUrl: 'url' }
return updateConfiguration({
baseUrl: 'url',
redirectUrlPrefixes: [],
maxPerPage: null,
minPasswordLength: undefined,
senderEmail: NaN,
smtpUsername: ''
}).then(() => {
expect(apiService.authenticatedRequest).toBeCalledWith({
path: '/configuration.update',
data: {
base_url: 'url',
redirect_url_prefixes: [],
smtp_username: ''
}
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule EWalletConfig.FileStorageSettingsLoader do
end

defp load_file_storage("aws", app) do
cleanup_aws()
cleanup_gcs()

aws_bucket = Application.get_env(app, :aws_bucket)
Expand All @@ -55,6 +56,7 @@ defmodule EWalletConfig.FileStorageSettingsLoader do

defp load_file_storage("gcs", app) do
cleanup_aws()
cleanup_gcs()

gcs_bucket = Application.get_env(app, :gcs_bucket)
gcs_credentials = Application.get_env(app, :gcs_credentials)
Expand All @@ -67,8 +69,9 @@ defmodule EWalletConfig.FileStorageSettingsLoader do
end

defp load_file_storage("local", _app) do
cleanup_gcs()
cleanup_aws()
cleanup_gcs()

Application.put_env(:arc, :storage, EWalletConfig.Storage.Local)
end

Expand All @@ -77,6 +80,7 @@ defmodule EWalletConfig.FileStorageSettingsLoader do
end

defp cleanup_gcs do
_ = GenServer.call(EWalletConfig.FileStorageSupervisor, :stop_goth)
Application.delete_env(:arc, :storage)
Application.delete_env(:arc, :bucket)
Application.delete_env(:goth, :json)
Expand Down
4 changes: 1 addition & 3 deletions apps/ewallet_config/lib/ewallet_config/setting.ex
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ defmodule EWalletConfig.Setting do
Map.put(attrs, :data, %{value: value})
end

defp cast_value(attrs, _) do
Map.put(attrs, :data, %{value: nil})
end
defp cast_value(attrs, _), do: attrs

defp cast_value(%{secret: true, value: value} = attrs) do
Map.put(attrs, :encrypted_data, %{value: value})
Expand Down
11 changes: 10 additions & 1 deletion apps/ewallet_config/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule EWalletConfig.MixProject do
def application do
[
extra_applications: [:logger],
mod: {EWalletConfig.Application, []}
mod: {EWalletConfig.Application, []},
]
end

Expand All @@ -50,6 +50,15 @@ defmodule EWalletConfig.MixProject do
{:poison, "~> 3.1"},
{:postgrex, ">= 0.0.0"},
{:utils, in_umbrella: true},

# arc GCS dependencies
{:arc_gcs, github: "omisego/arc_gcs"},

# arc AWS dependencies
{:ex_aws, "~> 2.0"},
{:ex_aws_s3, "~> 2.0"},
{:hackney, "~> 1.6"},
{:sweet_xml, "~> 0.6"},
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule EWalletDB.Repo.Seeds.SettingSeed do
end

defp sync_position(key, %{position: old_pos}, %{position: new_pos}) when is_integer(old_pos) and is_integer(new_pos) and old_pos != new_pos do
case Setting.update(key, %{position: new_pos}) do
case Setting.update(key, %{position: new_pos, originator: %EWalletDB.Seeder{}}) do
{:ok, _} -> {:ok, old_pos, new_pos}
{:error, changeset} -> {:error, changeset}
end
Expand Down
32 changes: 32 additions & 0 deletions apps/ewallet_config/test/ewallet_config/setting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,38 @@ defmodule EWalletConfig.SettingTest do
assert setting.value == "xyz"
end

test "updates only the position and leave the value unchanged" do
{:ok, _} =
Setting.insert(%{
key: "my_key",
value: "abc",
type: "string",
position: 1,
originator: %System{}
})

{res, setting} = Setting.update("my_key", %{position: 2, originator: %System{}})

assert res == :ok
assert setting.value == "abc"
assert setting.position == 2
end

test "can update a value to nil" do
{:ok, _} =
Setting.insert(%{
key: "my_key",
value: "abc",
type: "string",
originator: %System{}
})

{res, setting} = Setting.update("my_key", %{value: nil, originator: %System{}})

assert res == :ok
assert setting.value == nil
end

test "fails to update a select setting when the value is invalid" do
{:ok, _} =
Setting.insert(%{
Expand Down
9 changes: 0 additions & 9 deletions apps/ewallet_db/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ defmodule EWalletDB.Mixfile do
{:poison, "~> 3.1"},
{:postgrex, ">= 0.0.0"},
{:timex, "~> 3.0"},

# arc GCS dependencies
{:arc_gcs, "~> 0.0.3", runtime: false},

# arc AWS dependencies
{:ex_aws, "~> 2.0"},
{:ex_aws_s3, "~> 2.0"},
{:hackney, "~> 1.6"},
{:sweet_xml, "~> 0.6"},
]
end

Expand Down
4 changes: 2 additions & 2 deletions apps/local_ledger/lib/local_ledger/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ defmodule LocalLedger.Application do
import Supervisor.Spec
DeferredConfig.populate(:local_ledger)

settings = Application.get_env(:ewallet, :settings)
Config.register_and_load(:ewallet, settings)
settings = Application.get_env(:local_ledger, :settings)
Config.register_and_load(:local_ledger, settings)

children =
case Application.get_env(:local_ledger, LocalLedger.Scheduler) do
Expand Down
Loading

0 comments on commit b97272a

Please sign in to comment.