Add start to Token creation feature
This commit is contained in:
parent
516f4c12fa
commit
a5a5b29d07
@ -3,7 +3,7 @@ class CanistersController < ApplicationController
|
|||||||
|
|
||||||
# GET /canisters or /canisters.json
|
# GET /canisters or /canisters.json
|
||||||
def index
|
def index
|
||||||
@canisters = authorize Canister.all
|
authorize @canisters = policy_scope(Canister)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /canisters/1 or /canisters/1.json
|
# GET /canisters/1 or /canisters/1.json
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
class TokensController < ApplicationController
|
class TokensController < ApplicationController
|
||||||
before_action :set_token, only: %i[ show edit update destroy refresh ]
|
before_action :set_token, only: %i[ show edit update destroy refresh launch]
|
||||||
|
|
||||||
# GET /tokens or /tokens.json
|
# GET /tokens or /tokens.json
|
||||||
def index
|
def index
|
||||||
authorize @tokens = Token.all
|
authorize @tokens = Token.all
|
||||||
|
@mytokens = Token.where(ownable_id: current_user.soft_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /tokens/1 or /tokens/1.json
|
# GET /tokens/1 or /tokens/1.json
|
||||||
@ -13,6 +14,10 @@ class TokensController < ApplicationController
|
|||||||
|
|
||||||
# GET /tokens/new
|
# GET /tokens/new
|
||||||
def new
|
def new
|
||||||
|
authorize @token = Token.new(ownable_id: current_user.soft_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_existing
|
||||||
authorize @token = Token.new
|
authorize @token = Token.new
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -21,6 +26,11 @@ class TokensController < ApplicationController
|
|||||||
authorize @token
|
authorize @token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def launch
|
||||||
|
authorize @token
|
||||||
|
redirect_to @token, notice: "Launch function coming soon!"
|
||||||
|
end
|
||||||
|
|
||||||
def refresh
|
def refresh
|
||||||
authorize @token
|
authorize @token
|
||||||
# if call icrc1_metadata #icrc1
|
# if call icrc1_metadata #icrc1
|
||||||
@ -74,13 +84,13 @@ class TokensController < ApplicationController
|
|||||||
# POST /tokens or /tokens.json
|
# POST /tokens or /tokens.json
|
||||||
def create
|
def create
|
||||||
authorize @token = Token.new(token_params)
|
authorize @token = Token.new(token_params)
|
||||||
|
@token.canister_id = nil if @token.canister_id.blank?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @token.save
|
if @token.save
|
||||||
format.html { redirect_to refresh_token_url(@token), notice: "Token was successfully created." }
|
format.html { redirect_to (request.referrer.split("/")[-1].match("add_existing") ? refresh_token_url(@token) : @token), notice: "Token was successfully created." }
|
||||||
format.json { render :show, status: :created, location: @token }
|
format.json { render :show, status: :created, location: @token }
|
||||||
else
|
else
|
||||||
format.html { render :new, status: :unprocessable_entity }
|
format.html { render (request.referrer.split("/")[-1].match("add_existing") ? :add_existing : :new), status: :unprocessable_entity }
|
||||||
format.json { render json: @token.errors, status: :unprocessable_entity }
|
format.json { render json: @token.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -89,6 +99,7 @@ class TokensController < ApplicationController
|
|||||||
# PATCH/PUT /tokens/1 or /tokens/1.json
|
# PATCH/PUT /tokens/1 or /tokens/1.json
|
||||||
def update
|
def update
|
||||||
authorize @token
|
authorize @token
|
||||||
|
@token.canister_id = nil if @token.canister_id.blank?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @token.update(token_params)
|
if @token.update(token_params)
|
||||||
format.html { redirect_to token_url(@token), notice: "Token was successfully updated." }
|
format.html { redirect_to token_url(@token), notice: "Token was successfully updated." }
|
||||||
@ -119,6 +130,6 @@ class TokensController < ApplicationController
|
|||||||
|
|
||||||
# Only allow a list of trusted parameters through.
|
# Only allow a list of trusted parameters through.
|
||||||
def token_params
|
def token_params
|
||||||
params.require(:token).permit(:canister_id, :standard, :symbol, :name, :total_supply, :decimals, :transfer_fee, :logo_url)
|
params.require(:token).permit(:canister_id, :standard, :symbol, :name, :total_supply, :decimals, :transfer_fee, :logo_url, :ownable_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
class Token < ActiveRecord::Base
|
class Token < ActiveRecord::Base
|
||||||
enum standard: [:dip20, :icrc1, :unknown]
|
enum standard: [:dip20, :icrc1, :unknown]
|
||||||
validates :canister_id, presence: true, uniqueness: true
|
validates :canister_id, uniqueness: true, allow_nil: true
|
||||||
|
|
||||||
def transfer_fee_to_f
|
def transfer_fee_to_f
|
||||||
if self.transfer_fee.present?
|
if self.transfer_fee.present?
|
||||||
|
|||||||
@ -6,6 +6,26 @@ class CanisterPolicy
|
|||||||
@model = model
|
@model = model
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Scope
|
||||||
|
def initialize(user, scope)
|
||||||
|
@user = user
|
||||||
|
@scope = scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve
|
||||||
|
if user.admin?
|
||||||
|
scope.all
|
||||||
|
else
|
||||||
|
scope.where(user: user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
attr_reader :user, :scope
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def index?
|
def index?
|
||||||
@current_user.admin? || true
|
@current_user.admin? || true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -34,26 +34,34 @@ class TokenPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
@user.admin?
|
@user.admin? || true
|
||||||
end
|
end
|
||||||
|
|
||||||
def new?
|
def new?
|
||||||
@user.admin?
|
@user.admin? || true
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_existing?
|
||||||
|
new?
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit?
|
def edit?
|
||||||
@user.admin?
|
@user.admin? || @token.ownable_id == @user.soft_token
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
@user.admin?
|
@user.admin? || edit?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
@user.admin?
|
@user.admin? || @token.ownable_id == @user.soft_token
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh?
|
def refresh?
|
||||||
true
|
@token.canister_id.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def launch?
|
||||||
|
@user.admin? || true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
<li><%= link_to 'Tokens', tokens_path %></li>
|
<li><%= link_to 'Tokens', tokens_path %></li>
|
||||||
<li><%= link_to 'Profiles', profiles_path %></li>
|
<li><%= link_to 'Profiles', profiles_path %></li>
|
||||||
<li><%= link_to 'Projects', projects_path %></li>
|
<li><%= link_to 'Projects', projects_path %></li>
|
||||||
|
<li><%= link_to 'Canisters', canisters_path %></li>
|
||||||
<li><%= link_to 'Doodads', doodads_path, data: { turbo: false } %></li>
|
<li><%= link_to 'Doodads', doodads_path, data: { turbo: false } %></li>
|
||||||
<% if policy(:bot).index? %>
|
<% if policy(:bot).index? %>
|
||||||
<li><%= link_to 'Bots', bots_path %></li>
|
<li><%= link_to 'Bots', bots_path %></li>
|
||||||
|
|||||||
8
app/views/tokens/_existing_token_form.html.haml
Normal file
8
app/views/tokens/_existing_token_form.html.haml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
= simple_form_for(@token) do |f|
|
||||||
|
= f.error_notification
|
||||||
|
|
||||||
|
.form-inputs
|
||||||
|
= f.input :canister_id
|
||||||
|
|
||||||
|
.form-actions
|
||||||
|
= f.button :submit, "Add Token"
|
||||||
@ -2,8 +2,9 @@
|
|||||||
= f.error_notification
|
= f.error_notification
|
||||||
|
|
||||||
.form-inputs
|
.form-inputs
|
||||||
= f.input :canister_id
|
-# = f.input :canister_id
|
||||||
= f.input :standard
|
= f.select(:standard, Token.standards.keys.map {|standard| [standard.titleize,standard]})
|
||||||
|
= f.hidden_field :ownable_id
|
||||||
= f.input :symbol
|
= f.input :symbol
|
||||||
= f.input :name
|
= f.input :name
|
||||||
= f.input :total_supply
|
= f.input :total_supply
|
||||||
@ -11,5 +12,4 @@
|
|||||||
= f.input :transfer_fee
|
= f.input :transfer_fee
|
||||||
= f.input :logo_url
|
= f.input :logo_url
|
||||||
|
|
||||||
.form-actions
|
= f.button :submit
|
||||||
= f.button :submit, "Add Token"
|
|
||||||
|
|||||||
5
app/views/tokens/add_existing.html.haml
Normal file
5
app/views/tokens/add_existing.html.haml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
%h1 Add existing token
|
||||||
|
|
||||||
|
= render 'existing_token_form'
|
||||||
|
|
||||||
|
= link_to 'Back', tokens_path
|
||||||
@ -1,9 +1,50 @@
|
|||||||
|
- if @mytokens.present?
|
||||||
|
.contain
|
||||||
|
%h1 My Tokens
|
||||||
|
|
||||||
|
.table-container
|
||||||
|
.contain
|
||||||
|
%table.token-index
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th Logo
|
||||||
|
%th Symbol
|
||||||
|
%th Name
|
||||||
|
%th Canister
|
||||||
|
%th Standard
|
||||||
|
%th Total supply
|
||||||
|
%th Decimals
|
||||||
|
%th Transfer fee
|
||||||
|
- if policy(Token).new?
|
||||||
|
%th
|
||||||
|
%th
|
||||||
|
%th
|
||||||
|
|
||||||
|
%tbody
|
||||||
|
- @mytokens.each do |token|
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
= link_to token do
|
||||||
|
%img.token-logo{src: token.logo_url}
|
||||||
|
%td= link_to token.symbol, token
|
||||||
|
%td= token.name
|
||||||
|
%td= token.canister_id ? token.canister_id : "Prelaunch"
|
||||||
|
%td= token.standard
|
||||||
|
%td= token.total_supply
|
||||||
|
%td= token.decimals
|
||||||
|
%td= token.transfer_fee_to_f
|
||||||
|
- if policy(token).update?
|
||||||
|
%td= link_to 'Show', token
|
||||||
|
%td= link_to 'Edit', edit_token_path(token)
|
||||||
|
%td= link_to 'Destroy', token, method: :delete, data: { confirm: 'Are you sure?' }
|
||||||
|
|
||||||
.contain
|
.contain
|
||||||
%h1 Listing tokens
|
%h1 Listing tokens
|
||||||
|
|
||||||
%div{style: "align-self: start;"}
|
%div{style: "align-self: start;"}
|
||||||
- if policy(Token).new?
|
- if policy(Token).new?
|
||||||
= link_to 'Add Token', new_token_path
|
= link_to 'Add Existing Token', add_existing_new_token_path
|
||||||
|
= link_to 'Create New Token', new_token_path + "?create"
|
||||||
|
|
||||||
.table-container
|
.table-container
|
||||||
.contain
|
.contain
|
||||||
@ -18,7 +59,7 @@
|
|||||||
%th Total supply
|
%th Total supply
|
||||||
%th Decimals
|
%th Decimals
|
||||||
%th Transfer fee
|
%th Transfer fee
|
||||||
- if policy(@tokens).update?
|
- if policy(Token).new?
|
||||||
%th
|
%th
|
||||||
%th
|
%th
|
||||||
%th
|
%th
|
||||||
@ -31,7 +72,7 @@
|
|||||||
%img.token-logo{src: token.logo_url}
|
%img.token-logo{src: token.logo_url}
|
||||||
%td= link_to token.symbol, token
|
%td= link_to token.symbol, token
|
||||||
%td= token.name
|
%td= token.name
|
||||||
%td= token.canister_id
|
%td= token.canister_id ? token.canister_id : "Prelaunch"
|
||||||
%td= token.standard
|
%td= token.standard
|
||||||
%td= token.total_supply
|
%td= token.total_supply
|
||||||
%td= token.decimals
|
%td= token.decimals
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
%h1 Add token
|
.contain
|
||||||
|
%h1 Create new token
|
||||||
|
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,29 @@
|
|||||||
.contain
|
.contain
|
||||||
%h1
|
%h1
|
||||||
= @token.name
|
= @token.name
|
||||||
|
Token
|
||||||
|
|
||||||
- if policy(@token).edit?
|
- if policy(@token).edit?
|
||||||
= link_to 'Edit', edit_token_path(@token)
|
= link_to 'Edit', edit_token_path(@token)
|
||||||
|
- if policy(@token).destroy?
|
||||||
= link_to 'Delete', @token, method: :delete, data: { confirm: 'Are you sure?' }
|
= link_to 'Delete', @token, method: :delete, data: { confirm: 'Are you sure?' }
|
||||||
|
|
||||||
= link_to "Refresh Data", refresh_token_path(@token)
|
- if policy(@token).launch?
|
||||||
|
= button_to "Launch", launch_token_path(@token), method: :get
|
||||||
|
%span on IC mainnet
|
||||||
|
|
||||||
|
- if policy(@token).refresh?
|
||||||
|
= link_to "Refresh Data", refresh_token_path(@token)
|
||||||
|
|
||||||
.token-show
|
.token-show
|
||||||
%p
|
- if @token.canister_id
|
||||||
%b Canister:
|
%p
|
||||||
= @token.canister_id
|
%b Canister:
|
||||||
|
= @token.canister_id
|
||||||
|
- else
|
||||||
|
%p
|
||||||
|
%b Status:
|
||||||
|
Prelaunch
|
||||||
%p
|
%p
|
||||||
%b Logo:
|
%b Logo:
|
||||||
- if @token.logo_url.present?
|
- if @token.logo_url.present?
|
||||||
@ -39,4 +51,7 @@
|
|||||||
%p
|
%p
|
||||||
%b Holders:
|
%b Holders:
|
||||||
= @token.holder_number
|
= @token.holder_number
|
||||||
|
%p
|
||||||
|
%b Owned by:
|
||||||
|
= @token.ownable_id
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,10 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :tokens do
|
resources :tokens do
|
||||||
|
get 'add_existing', on: :new
|
||||||
member do
|
member do
|
||||||
get 'refresh'
|
get 'refresh'
|
||||||
|
get 'launch'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :projects
|
resources :projects
|
||||||
|
|||||||
5
db/migrate/20231208165729_add_ownable_id_to_token.rb
Normal file
5
db/migrate/20231208165729_add_ownable_id_to_token.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class AddOwnableIdToToken < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
add_column :tokens, :ownable_id, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2023_12_08_104330) do
|
ActiveRecord::Schema[7.1].define(version: 2023_12_08_165729) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@ -251,6 +251,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_08_104330) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "logo_url"
|
t.string "logo_url"
|
||||||
t.integer "holder_number"
|
t.integer "holder_number"
|
||||||
|
t.string "ownable_id"
|
||||||
t.index ["canister_id"], name: "index_tokens_on_canister_id", unique: true
|
t.index ["canister_id"], name: "index_tokens_on_canister_id", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user