Add dip20 holder count and improve token show style

This commit is contained in:
Jesse C. Fisher 2023-12-08 10:48:09 +00:00 committed by TheNeedful-DO
parent a6ddfcac24
commit 50b2d3c666
6 changed files with 64 additions and 32 deletions

View File

@ -1,5 +1,6 @@
.token-logo
max-width: 100%
width: 4.20rem
.table-container
background: #39272799
@ -12,3 +13,6 @@ table.token-index
.token-logo
max-width: 4rem
vertical-align: middle
.token-show
font-size: 1rem

View File

@ -26,11 +26,17 @@ class TokensController < ApplicationController
# 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?
# TODO: Use getTokenInfo instead of getMetadata
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
# TODO: Use getTokenInfo instead of getMetadata
tokenInfo = `dfx canister --network ic call #{@token.canister_id} getTokenInfo 2>&1`
@token.holder_number = tokenInfo.lines[2].split[2]
@token.transfer_fee = metadata.lines[2].split[2].to_i
@token.decimals = metadata.lines[3].split[2]
# @token.owner = metadata.lines[4].split[3]

View File

@ -9,4 +9,13 @@ class Token < ActiveRecord::Base
return nil
end
end
def get_holder_number
if self.standard == "dip20"
tokenInfo = `dfx canister --network ic call #{self.canister_id} getTokenInfo 2>&1`
tokenInfo.lines[2].split[2]
else
"Get holder number coming soon."
end
end
end

View File

@ -1,3 +1,6 @@
.contain
%h1
= @token.name
- if policy(@token).edit?
= link_to 'Edit', edit_token_path(@token)
@ -5,6 +8,7 @@
= link_to "Refresh Data", refresh_token_path(@token)
.token-show
%p
%b Canister:
= @token.canister_id
@ -32,4 +36,7 @@
%p
%b Transfer fee:
= @token.transfer_fee_to_f
%p
%b Holders:
= @token.holder_number

View File

@ -0,0 +1,5 @@
class AddHolderNumberToToken < ActiveRecord::Migration[7.1]
def change
add_column :tokens, :holder_number, :integer
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2023_12_04_083004) do
ActiveRecord::Schema[7.1].define(version: 2023_12_08_104330) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -250,6 +250,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_04_083004) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "logo_url"
t.integer "holder_number"
t.index ["canister_id"], name: "index_tokens_on_canister_id", unique: true
end