Skip to content

Commit

Permalink
fix(station): address multi chain review comments (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
olaszakos authored Nov 5, 2024
1 parent ffbfad6 commit fcb98d1
Show file tree
Hide file tree
Showing 32 changed files with 202 additions and 178 deletions.
13 changes: 7 additions & 6 deletions apps/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"format": "concurrently -n prettier,eslint -c auto \"prettier --ignore-path ../../.prettierignore --write .\" \"eslint --ext .js,.vue,.ts,.cjs --fix .\""
},
"dependencies": {
"@dfinity/agent": "2.1.2",
"@dfinity/auth-client": "2.1.2",
"@dfinity/candid": "2.1.2",
"@dfinity/identity": "2.1.2",
"@dfinity/principal": "2.1.2",
"@dfinity/ledger-icrc": "2.6.1",
"@dfinity/agent": "1.4.0",
"@dfinity/auth-client": "1.4.0",
"@dfinity/candid": "1.4.0",
"@dfinity/identity": "1.4.0",
"@dfinity/principal": "1.4.0",
"@dfinity/ledger-icrc": "2.3.3",
"@dfinity/utils": "2.3.1",
"@dfinity/didc": "0.0.2",
"@mdi/font": "7.4.47",
"@mdi/js": "7.4.47",
Expand Down
1 change: 0 additions & 1 deletion apps/wallet/src/components/assets/AssetDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ const save = async (): Promise<void> => {
},
],
blockchain: [assertAndReturn(asset.value.blockchain, 'blockchain')],
decimals: [assertAndReturn(asset.value.decimals, 'decimals')],
name: [assertAndReturn(asset.value.name, 'name')],
symbol: [assertAndReturn(asset.value.symbol, 'symbol')],
standards: [assertAndReturn(asset.value.standards, 'standards')],
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/components/assets/AssetForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
:label="$t('pages.assets.forms.decimals')"
variant="filled"
density="comfortable"
:disabled="isViewMode"
:disabled="isViewMode || !!model.id"
:prepend-icon="mdiDecimal"
:rules="[requiredRule]"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ const fetchDetails = async () => {
entry.symbol = props.operation.input.symbol[0];
}
if (props.operation.input.decimals !== undefined) {
entry.decimals = props.operation.input.decimals[0];
}
if (props.operation.input.standards && props.operation.input.standards.length > 0) {
entry.standards = props.operation.input.standards[0];
}
Expand Down
12 changes: 4 additions & 8 deletions apps/wallet/src/generated/station/station.did
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ type ListAddressBookEntriesInput = record {
blockchain : opt text;
// The labels to search for, if provided only address book entries with the given labels will be returned.
labels : opt vec text;
// The address formats to search for.
address_formats : opt vec text;
// The pagination parameters.
paginate : opt PaginationInput;
};
Expand Down Expand Up @@ -1754,9 +1756,7 @@ type Asset = record {
symbol : AssetSymbol;
// The asset name (e.g. `Internet Computer`, `Bitcoin`, `Ethereum`, etc.)
name : text;
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`),
// also, in the case of non-native assets, it can contain other required
// information (e.g. `{"address": "0x1234"}`).
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`).
metadata : vec AssetMetadata;
// The number of decimals used by the asset (e.g. `8` for `BTC`, `18` for `ETH`, etc.).
decimals : nat32;
Expand Down Expand Up @@ -2239,9 +2239,7 @@ type AddAssetOperationInput = record {
symbol : AssetSymbol;
// The asset name (e.g. `Internet Computer`, `Bitcoin`, `Ethereum`, etc.)
name : text;
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`),
// also, in the case of non-native assets, it can contain other required
// information (e.g. `{"address": "0x1234"}`).
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`).
metadata : vec AssetMetadata;
// The number of decimals used by the asset (e.g. `8` for `BTC`, `18` for `ETH`, etc.).
decimals : nat32;
Expand All @@ -2265,8 +2263,6 @@ type EditAssetOperationInput = record {
standards : opt vec text;
// The asset symbol, e.g. "ICP" or "BTC".
symbol : opt AssetSymbol;
// The number of decimals used by the asset (e.g. `8` for `BTC`, `18` for `ETH`, etc.).
decimals : opt nat32;
// The metadata to change.
change_metadata : opt ChangeMetadata;
};
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/generated/station/station.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ export interface EditAddressBookEntryOperationInput {
}
export interface EditAssetOperation { 'input' : EditAssetOperationInput }
export interface EditAssetOperationInput {
'decimals' : [] | [number],
'standards' : [] | [Array<string>],
'name' : [] | [string],
'blockchain' : [] | [string],
Expand Down Expand Up @@ -703,6 +702,7 @@ export type ListAccountsResult = {
{ 'Err' : Error };
export interface ListAddressBookEntriesInput {
'ids' : [] | [Array<UUID>],
'address_formats' : [] | [Array<string>],
'labels' : [] | [Array<string>],
'blockchain' : [] | [string],
'addresses' : [] | [Array<string>],
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/generated/station/station.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ export const idlFactory = ({ IDL }) => {
'ReplaceAllBy' : IDL.Vec(AssetMetadata),
});
const EditAssetOperationInput = IDL.Record({
'decimals' : IDL.Opt(IDL.Nat32),
'standards' : IDL.Opt(IDL.Vec(IDL.Text)),
'name' : IDL.Opt(IDL.Text),
'blockchain' : IDL.Opt(IDL.Text),
Expand Down Expand Up @@ -1181,6 +1180,7 @@ export const idlFactory = ({ IDL }) => {
});
const ListAddressBookEntriesInput = IDL.Record({
'ids' : IDL.Opt(IDL.Vec(UUID)),
'address_formats' : IDL.Opt(IDL.Vec(IDL.Text)),
'labels' : IDL.Opt(IDL.Vec(IDL.Text)),
'blockchain' : IDL.Opt(IDL.Text),
'addresses' : IDL.Opt(IDL.Vec(IDL.Text)),
Expand Down
1 change: 0 additions & 1 deletion apps/wallet/src/pages/AccountAssetPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ const loadTransfers = async (): Promise<
) {
return [];
}
// const firstAddress = addresses.value[0];
const transfers = await chainApi.value.fetchTransfers({
fromDt: convertDate(filters.value.created.from, {
time: 'start-of-day',
Expand Down
11 changes: 10 additions & 1 deletion apps/wallet/src/services/station.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,15 @@ export class StationService {
}

async listAddressBook(
{ limit, offset, blockchain, labels, ids, addresses }: ListAddressBookEntriesArgs = {},
{
limit,
offset,
blockchain,
labels,
ids,
addresses,
address_formats,
}: ListAddressBookEntriesArgs = {},
verifiedCall = false,
): Promise<ExtractOk<ListAddressBookEntriesResult>> {
const actor = verifiedCall ? this.verified_actor : this.actor;
Expand All @@ -566,6 +574,7 @@ export class StationService {
labels: labels ? [labels] : [],
addresses: addresses ? [addresses] : [],
ids: ids ? [ids] : [],
address_formats: address_formats ? [address_formats] : [],
});

if (variantIs(result, 'Err')) {
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/types/station.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface ListAddressBookEntriesArgs {
blockchain?: string;
labels?: [];
ids?: UUID[];
address_formats?: string[];
}

export interface ListAssetsArgs {
Expand Down
12 changes: 4 additions & 8 deletions core/station/api/spec.did
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ type ListAddressBookEntriesInput = record {
blockchain : opt text;
// The labels to search for, if provided only address book entries with the given labels will be returned.
labels : opt vec text;
// The address formats to search for.
address_formats : opt vec text;
// The pagination parameters.
paginate : opt PaginationInput;
};
Expand Down Expand Up @@ -1754,9 +1756,7 @@ type Asset = record {
symbol : AssetSymbol;
// The asset name (e.g. `Internet Computer`, `Bitcoin`, `Ethereum`, etc.)
name : text;
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`),
// also, in the case of non-native assets, it can contain other required
// information (e.g. `{"address": "0x1234"}`).
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`).
metadata : vec AssetMetadata;
// The number of decimals used by the asset (e.g. `8` for `BTC`, `18` for `ETH`, etc.).
decimals : nat32;
Expand Down Expand Up @@ -2239,9 +2239,7 @@ type AddAssetOperationInput = record {
symbol : AssetSymbol;
// The asset name (e.g. `Internet Computer`, `Bitcoin`, `Ethereum`, etc.)
name : text;
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`),
// also, in the case of non-native assets, it can contain other required
// information (e.g. `{"address": "0x1234"}`).
// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`).
metadata : vec AssetMetadata;
// The number of decimals used by the asset (e.g. `8` for `BTC`, `18` for `ETH`, etc.).
decimals : nat32;
Expand All @@ -2265,8 +2263,6 @@ type EditAssetOperationInput = record {
standards : opt vec text;
// The asset symbol, e.g. "ICP" or "BTC".
symbol : opt AssetSymbol;
// The number of decimals used by the asset (e.g. `8` for `BTC`, `18` for `ETH`, etc.).
decimals : opt nat32;
// The metadata to change.
change_metadata : opt ChangeMetadata;
};
Expand Down
1 change: 1 addition & 0 deletions core/station/api/src/address_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct ListAddressBookEntriesInputDTO {
pub blockchain: Option<String>,
pub labels: Option<Vec<String>>,
pub paginate: Option<PaginationInput>,
pub address_formats: Option<Vec<String>>,
}

#[derive(CandidType, serde::Serialize, Deserialize, Debug, Clone)]
Expand Down
5 changes: 1 addition & 4 deletions core/station/api/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ pub struct AssetDTO {
pub standards: Vec<String>,
/// The asset name (e.g. `Internet Computer`, `Bitcoin`, `Ethereum`, etc.)
pub name: String,
/// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`),
/// also, in the case of non-native assets, it can contain other required
/// information (e.g. `{"address": "0x1234"}`).
/// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`).
pub metadata: Vec<MetadataDTO>,
}

Expand Down Expand Up @@ -51,7 +49,6 @@ pub struct EditAssetOperationInput {
pub blockchain: Option<String>,
pub standards: Option<Vec<String>>,
pub symbol: Option<String>,
pub decimals: Option<u32>,
pub change_metadata: Option<ChangeMetadataDTO>,
}

Expand Down
4 changes: 2 additions & 2 deletions core/station/impl/src/core/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ lazy_static! {
Resource::Asset(ResourceAction::Create),
),
(
Allow::user_groups(vec![*ADMIN_GROUP_ID]),
Allow::authenticated(),
Resource::Asset(ResourceAction::List),
),
(
Allow::user_groups(vec![*ADMIN_GROUP_ID]),
Allow::authenticated(),
Resource::Asset(ResourceAction::Read(ResourceId::Any)),
),
(
Expand Down
2 changes: 1 addition & 1 deletion core/station/impl/src/core/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl EnsureExternalCanister {
pub fn is_external_canister(
principal: Principal,
) -> Result<(), ExternalCanisterValidationError> {
// todo: look into Asset repository and exclude the ledger_canister_id's
// todo: add a mutable denylist for external canisters
if principal == Principal::management_canister()
|| principal == ic_cdk::api::id()
|| principal == MAINNET_LEDGER_CANISTER_ID
Expand Down
15 changes: 5 additions & 10 deletions core/station/impl/src/errors/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub enum AssetError {
/// The given blockchain is unknown to the system.
#[error(r#"The given blockchain is unknown to the system."#)]
UnknownBlockchain { blockchain: String },
/// The given blockchain standard is unknown to the system.
#[error(r#"The given blockchain standard is unknown to the system."#)]
UnknownBlockchainStandard { blockchain_standard: String },
/// The given token standard is unknown to the system.
#[error(r#"The given token standard is unknown to the system."#)]
UnknownTokenStandard { token_standard: String },
/// The asset has failed validation.
#[error(r#"The account has failed validation."#)]
ValidationError { info: String },
Expand All @@ -50,13 +50,8 @@ impl DetailableError for AssetError {
details.insert("blockchain".to_string(), blockchain.to_string());
Some(details)
}
AssetError::UnknownBlockchainStandard {
blockchain_standard,
} => {
details.insert(
"blockchain_standard".to_string(),
blockchain_standard.to_string(),
);
AssetError::UnknownTokenStandard { token_standard } => {
details.insert("token_standard".to_string(), token_standard.to_string());
Some(details)
}
AssetError::ValidationError { info } => {
Expand Down
12 changes: 11 additions & 1 deletion core/station/impl/src/mappers/address_book.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::str::FromStr;

use super::HelperMapper;
use crate::core::ic_cdk::next_time;
use crate::errors::MapperError;
use crate::mappers::blockchain::BlockchainMapper;
use crate::models::{
AddAddressBookEntryOperationInput, AddressBookEntry, AddressBookEntryCallerPrivileges,
ListAddressBookEntriesInput,
AddressFormat, ListAddressBookEntriesInput,
};
use orbit_essentials::types::UUID;
use orbit_essentials::utils::timestamp_to_rfc3339;
Expand Down Expand Up @@ -67,6 +69,14 @@ impl From<ListAddressBookEntriesInputDTO> for ListAddressBookEntriesInput {
}),
labels: input.labels,
addresses: input.addresses,
address_formats: input.address_formats.map(|address_formats| {
address_formats
.into_iter()
.map(|address_format| {
AddressFormat::from_str(&address_format).expect("Invalid address format")
})
.collect()
}),
ids: input.ids.map(|ids| {
ids.into_iter()
.map(|id| {
Expand Down
2 changes: 0 additions & 2 deletions core/station/impl/src/mappers/request_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,6 @@ impl From<EditAssetOperationInput> for station_api::EditAssetOperationInput {
asset_id: Uuid::from_bytes(input.asset_id).hyphenated().to_string(),
name: input.name,
symbol: input.symbol,
decimals: input.decimals,
change_metadata: input
.change_metadata
.map(|change_metadata| change_metadata.into()),
Expand All @@ -1618,7 +1617,6 @@ impl From<station_api::EditAssetOperationInput> for EditAssetOperationInput {
.as_bytes(),
name: input.name,
symbol: input.symbol,
decimals: input.decimals,
change_metadata: input
.change_metadata
.map(|change_metadata| change_metadata.into()),
Expand Down
3 changes: 2 additions & 1 deletion core/station/impl/src/models/address_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ impl AddressBookEntry {
}
}

#[derive(CandidType, Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone)]
pub struct ListAddressBookEntriesInput {
pub ids: Option<Vec<UUID>>,
pub addresses: Option<Vec<String>>,
pub blockchain: Option<Blockchain>,
pub labels: Option<Vec<String>>,
pub address_formats: Option<Vec<AddressFormat>>,
}

#[derive(CandidType, Deserialize, Debug, Clone)]
Expand Down
4 changes: 1 addition & 3 deletions core/station/impl/src/models/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ pub struct Asset {
pub name: String,
/// The number of decimal places that the asset supports (e.g. `8` for `BTC`, `18` for `ETH`, etc.)
pub decimals: u32,
/// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`),
/// also, in the case of non-native assets, it can contain other required
/// information (e.g. `{"address": "0x1234"}`).
/// The asset metadata (e.g. `{"logo": "https://example.com/logo.png"}`).
pub metadata: Metadata,
}

Expand Down
2 changes: 1 addition & 1 deletion core/station/impl/src/models/indexes/unique_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub enum UniqueIndexKey {
UserIdentity(Principal),
UserName(String),
AssetSymbolBlockchain(
String, // Symbol
String, // Blockchain
String, // Symbol
),
}

Expand Down
1 change: 0 additions & 1 deletion core/station/impl/src/models/request_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub struct EditAssetOperationInput {
pub asset_id: AssetId,
pub name: Option<String>,
pub symbol: Option<String>,
pub decimals: Option<u32>,
pub change_metadata: Option<ChangeMetadata>,
pub blockchain: Option<Blockchain>,
pub standards: Option<Vec<TokenStandard>>,
Expand Down
Loading

0 comments on commit fcb98d1

Please sign in to comment.