Add basic token canister parsing
This commit is contained in:
parent
a71010bf9f
commit
5cdc00206c
@ -114,8 +114,9 @@ header
|
|||||||
|
|
||||||
*, *:before, *:after
|
*, *:before, *:after
|
||||||
box-sizing: inherit
|
box-sizing: inherit
|
||||||
font-family: Impact, Anton, fantasy, sans-serif
|
|
||||||
font-weight: lighter
|
font-weight: lighter
|
||||||
|
body
|
||||||
|
font-family: Impact, Anton, fantasy, sans-serif
|
||||||
.eyecandy
|
.eyecandy
|
||||||
display: block
|
display: block
|
||||||
left: 0
|
left: 0
|
||||||
@ -224,5 +225,11 @@ textarea
|
|||||||
padding: 0 1em
|
padding: 0 1em
|
||||||
margin: 0 auto
|
margin: 0 auto
|
||||||
|
|
||||||
|
.table-container
|
||||||
|
max-width: 100%
|
||||||
|
overflow-x: auto
|
||||||
|
align-self: start
|
||||||
|
|
||||||
@import doodads
|
@import doodads
|
||||||
@import profiles
|
@import profiles
|
||||||
|
@import tokens
|
||||||
|
|||||||
5
app/assets/stylesheets/tokens.sass
Normal file
5
app/assets/stylesheets/tokens.sass
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.token-index
|
||||||
|
font-family: "monospace"
|
||||||
|
|
||||||
|
.token-logo
|
||||||
|
max-width: 100%
|
||||||
@ -1,3 +0,0 @@
|
|||||||
// Place all the styles related to the Tokens controller here.
|
|
||||||
// They will automatically be included in application.css.
|
|
||||||
// You can use Sass (SCSS) here: https://sass-lang.com/
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
class TokensController < ApplicationController
|
class TokensController < ApplicationController
|
||||||
before_action :set_token, only: %i[ show edit update destroy ]
|
before_action :set_token, only: %i[ show edit update destroy refresh ]
|
||||||
|
|
||||||
# GET /tokens or /tokens.json
|
# GET /tokens or /tokens.json
|
||||||
def index
|
def index
|
||||||
@ -21,6 +21,36 @@ class TokensController < ApplicationController
|
|||||||
authorize @token
|
authorize @token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def refresh
|
||||||
|
authorize @token
|
||||||
|
# if call icrc1_metadata #icrc1
|
||||||
|
metadata = `dfx canister --network ic call #{@token.canister_id} icrc1_metadata 2>&1`
|
||||||
|
if metadata.scan(/no update method/).present?
|
||||||
|
metadata = `dfx canister --network ic call #{@token.canister_id} getMetadata 2>&1`
|
||||||
|
if metadata.scan(/no update method/).present?
|
||||||
|
@token.standard = :unknown
|
||||||
|
else
|
||||||
|
@token.standard = :dip20
|
||||||
|
@token.transfer_fee = metadata.lines[2].split[2]
|
||||||
|
@token.decimals = metadata.lines[3].split[2]
|
||||||
|
# @token.owner = metadata.lines[4].split[3]
|
||||||
|
@token.logo_url = metadata.lines[5].split[2]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@token.standard = :icrc1
|
||||||
|
end
|
||||||
|
# elsif call getMetadata #dip20
|
||||||
|
respond_to do |format|
|
||||||
|
if @token.save
|
||||||
|
format.html { redirect_to token_url(@token), notice: "Token was successfully refreshed." }
|
||||||
|
format.json { render :show, status: :created, location: @token }
|
||||||
|
else
|
||||||
|
format.html { render :new, status: :unprocessable_entity }
|
||||||
|
format.json { render json: @token.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# 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)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
class Token < ActiveRecord::Base
|
class Token < ActiveRecord::Base
|
||||||
|
enum standard: [:dip20, :icrc1, :unknown]
|
||||||
validates :canister_id, presence: true, uniqueness: true
|
validates :canister_id, presence: true, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -53,4 +53,7 @@ class TokenPolicy
|
|||||||
@user.admin?
|
@user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def refresh?
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,37 +1,40 @@
|
|||||||
%h1 Listing tokens
|
.contain
|
||||||
|
%h1 Listing tokens
|
||||||
|
|
||||||
- if policy(Token).new?
|
%div{style: "align-self: start;"}
|
||||||
= link_to 'Add Token', new_token_path
|
- if policy(Token).new?
|
||||||
|
= link_to 'Add Token', new_token_path
|
||||||
|
|
||||||
%table
|
.table-container
|
||||||
%thead
|
%table.token-index
|
||||||
%tr
|
%thead
|
||||||
%th Logo
|
|
||||||
%th Canister
|
|
||||||
%th Standard
|
|
||||||
%th Symbol
|
|
||||||
%th Name
|
|
||||||
%th Total supply
|
|
||||||
%th Decimals
|
|
||||||
%th Transfer fee
|
|
||||||
- if policy(@tokens).update?
|
|
||||||
%th
|
|
||||||
%th
|
|
||||||
%th
|
|
||||||
|
|
||||||
%tbody
|
|
||||||
- @tokens.each do |token|
|
|
||||||
%tr
|
%tr
|
||||||
%td= token.logo_url
|
%th Logo
|
||||||
%td= token.canister_id
|
%th Canister
|
||||||
%td= token.standard
|
%th Standard
|
||||||
%td= token.symbol
|
%th Symbol
|
||||||
%td= token.name
|
%th Name
|
||||||
%td= token.total_supply
|
%th Total supply
|
||||||
%td= token.decimals
|
%th Decimals
|
||||||
%td= token.transfer_fee
|
%th Transfer fee
|
||||||
- if policy(token).update?
|
- if policy(@tokens).update?
|
||||||
%td= link_to 'Show', token
|
%th
|
||||||
%td= link_to 'Edit', edit_token_path(token)
|
%th
|
||||||
%td= link_to 'Destroy', token, method: :delete, data: { confirm: 'Are you sure?' }
|
%th
|
||||||
|
|
||||||
|
%tbody
|
||||||
|
- @tokens.each do |token|
|
||||||
|
%tr
|
||||||
|
%td= raw "<img class='token-logo' src=#{token.logo_url} />"
|
||||||
|
%td= link_to token.canister_id, token
|
||||||
|
%td= token.standard
|
||||||
|
%td= token.symbol
|
||||||
|
%td= token.name
|
||||||
|
%td= token.total_supply
|
||||||
|
%td= token.decimals
|
||||||
|
%td= token.transfer_fee
|
||||||
|
- 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?' }
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,18 @@
|
|||||||
%p#notice= notice
|
|
||||||
|
|
||||||
%p
|
- if policy(@token).edit?
|
||||||
%b Canister:
|
= link_to 'Edit', edit_token_path(@token)
|
||||||
= @token.logo_url
|
|
||||||
|
= link_to "Refresh Data", refresh_token_path(@token)
|
||||||
|
|
||||||
%p
|
%p
|
||||||
%b Canister:
|
%b Canister:
|
||||||
= @token.canister_id
|
= @token.canister_id
|
||||||
|
%p
|
||||||
|
%b Logo:
|
||||||
|
- if @token.logo_url.present?
|
||||||
|
-# %img{src: @token.logo_url}
|
||||||
|
-# :escaped
|
||||||
|
=raw "<img class='token-logo' src=#{@token.logo_url} />"
|
||||||
%p
|
%p
|
||||||
%b Standard:
|
%b Standard:
|
||||||
= @token.standard
|
= @token.standard
|
||||||
@ -25,6 +32,3 @@
|
|||||||
%b Transfer fee:
|
%b Transfer fee:
|
||||||
= @token.transfer_fee
|
= @token.transfer_fee
|
||||||
|
|
||||||
= link_to 'Edit', edit_token_path(@token)
|
|
||||||
\|
|
|
||||||
= link_to 'Back', tokens_path
|
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :social_links
|
resources :social_links
|
||||||
resources :profiles
|
resources :profiles
|
||||||
resources :tokens
|
resources :tokens do
|
||||||
|
member do
|
||||||
|
get 'refresh'
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :projects
|
resources :projects
|
||||||
resources :doodads
|
resources :doodads
|
||||||
resources :canisters
|
resources :canisters
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user