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

feat: OMG Network deposits from the admin panel #1222

Open
wants to merge 16 commits into
base: mederic-p/plasma-deposit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ defmodule AdminAPI.V1.BlockchainWalletControllerTest do
end)
end

test_with_auths "accepts string `amount` attribute" do
identifier = BlockchainHelper.rootchain_identifier()
hot_wallet = BlockchainWallet.get_primary_hot_wallet(identifier)

token =
insert(:external_blockchain_token,
blockchain_address: "0x0000000000000000000000000000000000000000"
)

adapter = BlockchainHelper.adapter()
{:ok, _adapter_pid} = adapter.server().start_link([])

attrs = %{
token_id: token.id,
amount: Integer.to_string(100),
address: hot_wallet.address,
idempotency_token: UUID.generate()
}

response = request("/blockchain_wallet.deposit_to_childchain", attrs)
assert response["success"]
assert response["data"]["from"]["amount"] == 100

transaction = Transaction.get(response["data"]["id"], preload: :blockchain_transaction)
{:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid)

{:ok, %{pid: blockchain_listener_pid}} =
adapter.lookup_listener(transaction.blockchain_transaction.hash)

on_exit(fn ->
:ok = GenServer.stop(pid)
:ok = GenServer.stop(blockchain_listener_pid)
end)
end

test_with_auths "fails to deposit with a missing address" do
token = insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ defmodule EWallet.TransactionGate.Childchain do

@eth BlockchainHelper.adapter().helper().default_token().address

def deposit(actor, %{"amount" => amount} = attrs) when is_integer(amount) do
def deposit(actor, %{"amount" => amount} = attrs)
when is_integer(amount) or is_binary(amount) do
case build_transaction_attrs(attrs) do
{:ok, attrs} ->
validation_tuple = address_validation_tuple(attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,47 @@ defmodule EWallet.TransactionGate.ChildchainTest do
end)
end

test "returns an error if the amount is not an integer" do
test "accepts a string amount", meta do
admin = insert(:admin, global_role: "super_admin")

primary_blockchain_token =
insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000")
insert(:token,
blockchain_status: "confirmed",
blockchain_address: "0x0000000000000000000000000000000000000000"
)

rootchain_identifier = BlockchainHelper.rootchain_identifier()

hot_wallet = BlockchainWallet.get_primary_hot_wallet(rootchain_identifier)

attrs = %{
"idempotency_token" => UUID.generate(),
"address" => hot_wallet.address,
"token_id" => primary_blockchain_token.id,
"amount" => "1",
"amount" => Integer.to_string(1),
"originator" => %System{}
}

{res, code, error} = TransactionGate.Childchain.deposit(admin, attrs)
assert res == :error
assert code == :invalid_parameter
assert error == "Invalid parameter provided. `amount` is required."
{:ok, transaction} = TransactionGate.Childchain.deposit(admin, attrs)

{:ok, vault_address} = BlockchainHelper.call(:get_childchain_eth_vault_address)

assert transaction.status == TransactionState.blockchain_submitted()
assert transaction.type == Transaction.deposit()
assert transaction.blockchain_transaction.rootchain_identifier == rootchain_identifier
assert transaction.blockchain_transaction.childchain_identifier == nil
assert transaction.from_blockchain_address == hot_wallet.address
assert transaction.to_blockchain_address == vault_address

{:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid)

{:ok, %{pid: blockchain_listener_pid}} =
meta[:adapter].lookup_listener(transaction.blockchain_transaction.hash)

# to update the transactions after the test is done.
on_exit(fn ->
:ok = GenServer.stop(pid)
:ok = GenServer.stop(blockchain_listener_pid)
end)
end
end
end
4 changes: 2 additions & 2 deletions apps/ewallet_config/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ config :ewallet_config,
value: "http://localhost:9656",
type: "string",
position: 210,
description: "The url used by the eWallet to interact with the OmiseGO Network's node."
description: "The URL for the OMG Network child chain."
},
"omisego_watcher_url" => %{
key: "omisego_watcher_url",
value: "http://localhost:7534",
type: "string",
position: 211,
description: "The url used by the eWallet to interact with the OmiseGO Network's watcher."
description: "The URL for the OMG Network information service."
},
"omisego_plasma_framework_address" => %{
key: "omisego_plasma_framework_address",
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/assets/src/omg-blockchain-wallet/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const selectBlockchainWalletById = state => id => state.blockchainWallets

export const selectBlockchainWalletsLoadingStatus = state => state.loadingStatus.blockchainWallets

export const selectPlasmaDepositByAddress = state => address => {
export const selectPlasmaDepositByAddress = address => state => {
return state.plasmaDeposits[address]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from 'react'
import { useDispatch } from 'react-redux'
import styled from 'styled-components'

import PopperRenderer from 'omg-popper'
import withDropdownState from 'omg-uikit/dropdown/withDropdownState'
import { openModal } from 'omg-modal/action'
import { Icon, Button } from 'omg-uikit'
import { DropdownBox } from 'omg-uikit/dropdown'

const DropdownItem = styled.div`
padding: 7px 10px;
padding-right: 20px;
font-size: 12px;
color: ${props => props.theme.colors.B100};
cursor: pointer;
i,
span {
vertical-align: middle;
display: inline-block;
}
:hover {
color: ${props => props.theme.colors.B400};
}
i {
margin-right: 5px;
}
`
const ButtonStyle = styled(Button)`
margin-left: 10px;
i {
margin-left: 10px;
margin-right: 0 !important;
}
`

interface BlockchainActionSelectorProps {
name: string
onClickButton: React.MouseEventHandler
open: boolean
actions: Array<{
name: string
modal: { id: string; args: {} }
icon: string
}>
fromAddress: string
}

const BlockchainActionSelector = ({
name,
actions,
open,
onClickButton,
fromAddress
}: BlockchainActionSelectorProps) => {
const dispatch = useDispatch()

const renderDropdown = () => {
return (
<DropdownBox>
{actions.map((action, index) => {
const onClick = () =>
dispatch(
openModal({
id: action.modal.id,
fromAddress,
...action.modal.args
})
)
return (
<DropdownItem key={index} onClick={onClick}>
<Icon name={action.icon} />
<span>{action.name}</span>
</DropdownItem>
)
})}
</DropdownBox>
)
}

const renderButton = () => {
return (
<ButtonStyle size="small" styleType="primary" onClick={onClickButton}>
<span>{name}</span>
{open ? <Icon name="Chevron-Up" /> : <Icon name="Chevron-Down" />}
</ButtonStyle>
)
}

return (
<PopperRenderer
offset="0px, 5px"
modifiers={{
flip: { enabled: false },
preventOverflow: { enabled: false }
}}
renderReference={renderButton}
open={open}
renderPopper={renderDropdown}
/>
)
}

export default withDropdownState(BlockchainActionSelector)

This file was deleted.

Loading