This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profiles): flag contacts with types like wallets (#495)
- Loading branch information
Brian Faust
committed
Jun 29, 2020
1 parent
86c4e4f
commit 3ddcc5e
Showing
13 changed files
with
311 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Contracts } from "@arkecosystem/platform-sdk"; | ||
|
||
import { Avatar } from "./avatar"; | ||
import { Profile } from "./profile"; | ||
import { Wallet } from "./wallet"; | ||
|
||
export interface ContactAddressProps { | ||
id: string; | ||
coin: string; | ||
network: string; | ||
name: string; | ||
address: string; | ||
} | ||
|
||
export class ContactAddress { | ||
readonly #data: ContactAddressProps; | ||
readonly #wallet: Contracts.WalletData; | ||
|
||
private constructor(data: ContactAddressProps, wallet: Contracts.WalletData) { | ||
this.#data = data; | ||
this.#wallet = wallet; | ||
} | ||
|
||
public static async make(data: ContactAddressProps, profile: Profile): Promise<ContactAddress> { | ||
const wallet: Wallet = profile.wallets().findByCoinWithNetwork(data.coin, data.network)[0]; | ||
|
||
if (!wallet) { | ||
throw new Error(`This profile does not contain any wallets for ${data.coin}/${data.network}.`); | ||
} | ||
|
||
return new ContactAddress(data, await wallet.wallet(data.address)); | ||
} | ||
|
||
public id(): string { | ||
return this.#data.id; | ||
} | ||
|
||
public coin(): string { | ||
return this.#data.coin; | ||
} | ||
|
||
public network(): string { | ||
return this.#data.network; | ||
} | ||
|
||
public name(): string { | ||
return this.#data.name; | ||
} | ||
|
||
public address(): string { | ||
return this.#data.address; | ||
} | ||
|
||
public avatar(): string { | ||
return Avatar.make(this.#data.address); | ||
} | ||
|
||
public isDelegate(): boolean { | ||
return this.#wallet.isDelegate(); | ||
} | ||
|
||
public isKnown(): boolean { | ||
return this.#wallet.isKnown(); | ||
} | ||
|
||
public isMultiSignature(): boolean { | ||
return this.#wallet.isMultiSignature(); | ||
} | ||
|
||
public isSecondSignature(): boolean { | ||
return this.#wallet.isSecondSignature(); | ||
} | ||
|
||
public toObject(): ContactAddressProps { | ||
return { | ||
id: this.id(), | ||
coin: this.coin(), | ||
network: this.network(), | ||
name: this.name(), | ||
address: this.address(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.