Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Aug 8, 2020
1 parent 4a208b5 commit f2db231
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 91 deletions.
10 changes: 0 additions & 10 deletions app/api/ada/lib/state-fetch/mockNetwork.js
Expand Up @@ -508,16 +508,6 @@ export function genGetPoolInfo(
if (poolId === mockPoolId) {
result[mockPoolId] = {
info: {
owner: encode(
'ed25519_pk',
toWords(Buffer.from('df1750df9b2df285fcfb50f4740657a18ee3af42727d410c37b86207', 'hex')),
Number.MAX_SAFE_INTEGER
),
pledge_address: encode(
'addr',
toWords(Buffer.from('29b68b190d8afa4a546004821be4a7bedb8b28e2041293c91f31a6d2', 'hex')),
Number.MAX_SAFE_INTEGER
),
name: 'Yoroi',
description: 'Yoroi is a light wallet for Cardano. It’s simple, fast and secure.',
ticker: 'YOROI',
Expand Down
21 changes: 2 additions & 19 deletions app/api/ada/lib/state-fetch/remoteFetcher.js
Expand Up @@ -290,31 +290,14 @@ export class RemoteFetcher implements IFetcher {
{
method: 'post',
data: {
ids: body.ids
poolIds: body.ids
},
headers: {
'yoroi-version': this.getLastLaunchVersion(),
'yoroi-locale': this.getCurrentLocale()
}
}
).then(response => {
// backend returns some weird response if the pool doesn't exist
// I change this to be just "null"
const newResult: PoolInfoResponse = {};
for (const key of Object.keys(response.data)) {
const backendValue = response.data[key];
if (backendValue === null) { // future proof in case API changes to return null
newResult[key] = null;
continue;
}
if (backendValue?.history.length === 0 && backendValue?.info?.pledge_address === null) {
newResult[key] = null;
continue;
}
newResult[key] = backendValue;
}
return newResult;
})
).then(response => response.data)
.catch((error) => {
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getPoolInfo)} error: ` + stringifyError(error));
throw new GetPoolInfoApiError();
Expand Down
12 changes: 4 additions & 8 deletions app/api/ada/lib/state-fetch/types.js
Expand Up @@ -148,13 +148,13 @@ export const ShelleyCertificateTypes = Object.freeze({
});

export type RemoteStakeRegistrationCert = {|
+stakeCredential: string, // hex
+rewardAddress: string, // hex
|};
export type RemoteStakeDeregistrationCert = {|
+stakeCredential: string, // hex
+rewardAddress: string, // hex
|};
export type RemoteStakeDelegationCert = {|
+stakeCredential: string, // hex
+rewardAddress: string, // hex
+poolKeyHash: string, // hex
|};
export type RemotePoolRegistrationCert = {|
Expand Down Expand Up @@ -194,8 +194,7 @@ export type RemoteGenesisKeyDelegationCert = {|
|};
export type RemoteMoveInstantaneousRewardsCert = {|
+pot: number | ('Reserve' | 'Treasury'),
+rewards: Array<string>, // stakeCredential hex
// +rewards: {| [stake_credential: string]: string /* coin */ |},
+rewards: {| [stake_credential: string]: string /* coin */ |},
|};
export type RemoteCertificate = {|
certIndex: number,
Expand Down Expand Up @@ -255,9 +254,6 @@ export type PoolInfoRequest = {|
ids: Array<string>
|};
export type RemotePoolInfo = {|
+owner: string, // bech32
+pledge_address: string, // bech32

// from pool metadata (off chain)
+name?: string,
+description?: string,
Expand Down
71 changes: 25 additions & 46 deletions app/api/ada/lib/storage/bridge/updateTransactions.js
Expand Up @@ -1814,7 +1814,7 @@ async function certificateToDb(
case ShelleyCertificateTypes.StakeRegistration: {
const stakeCredentials = RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Buffer.from(cert.stakeCredential, 'hex')
Buffer.from(cert.rewardAddress, 'hex')
)
)?.payment_cred();
if (stakeCredentials == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
Expand Down Expand Up @@ -1845,7 +1845,7 @@ async function certificateToDb(
case ShelleyCertificateTypes.StakeDeregistration: {
const stakeCredentials = RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Buffer.from(cert.stakeCredential, 'hex')
Buffer.from(cert.rewardAddress, 'hex')
)
)?.payment_cred();
if (stakeCredentials == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
Expand Down Expand Up @@ -1881,7 +1881,7 @@ async function certificateToDb(

const stakeCredentials = RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Buffer.from(cert.stakeCredential, 'hex')
Buffer.from(cert.rewardAddress, 'hex')
)
)?.payment_cred();
if (stakeCredentials == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
Expand Down Expand Up @@ -2152,49 +2152,28 @@ async function certificateToDb(
})();
if (pot == null) break;
const certPot = RustModule.WalletV4.MoveInstantaneousReward.new(pot);
// TODO: remove this block with the proper block when backend supports it
if (Array.isArray(cert.rewards)) {
for (const key of cert.rewards) {
const rewardAddress = RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Buffer.from(key, 'hex')
)
);
if (rewardAddress == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
const rewardAddrKey = existingAddressesMap.get(
Buffer.from(rewardAddress.to_address().to_bytes()).toString('hex')
);
if (rewardAddrKey != null) {
relatedAddressesInfo.push({
AddressId: rewardAddrKey,
Relation: CertificateRelation.REWARD_ADDRESS
});
}
}
} else {
for (const key of Object.keys(cert.rewards)) {
const rewardAddress = RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Buffer.from(key, 'hex')
)
);
if (rewardAddress == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
const stakeCredentials = rewardAddress.payment_cred();
if (stakeCredentials == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
certPot.insert(
stakeCredentials,
RustModule.WalletV4.BigNum.from_str(cert.rewards[key])
);

const rewardAddrKey = existingAddressesMap.get(
Buffer.from(rewardAddress.to_address().to_bytes()).toString('hex')
);
if (rewardAddrKey != null) {
relatedAddressesInfo.push({
AddressId: rewardAddrKey,
Relation: CertificateRelation.REWARD_ADDRESS
});
}
for (const key of Object.keys(cert.rewards)) {
const rewardAddress = RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Buffer.from(key, 'hex')
)
);
if (rewardAddress == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
const stakeCredentials = rewardAddress.payment_cred();
if (stakeCredentials == null) throw new Error(`${nameof(certificateToDb)} not a valid reward account`);
certPot.insert(
stakeCredentials,
RustModule.WalletV4.BigNum.from_str(cert.rewards[key])
);

const rewardAddrKey = existingAddressesMap.get(
Buffer.from(rewardAddress.to_address().to_bytes()).toString('hex')
);
if (rewardAddrKey != null) {
relatedAddressesInfo.push({
AddressId: rewardAddrKey,
Relation: CertificateRelation.REWARD_ADDRESS
});
}
}
const certificate = RustModule.WalletV4.MoveInstantaneousRewardsCert.new(certPot);
Expand Down
8 changes: 4 additions & 4 deletions app/components/wallet/WalletRestoreVerifyDialog.js
Expand Up @@ -126,7 +126,7 @@ export default class WalletRestoreVerifyDialog extends Component<Props> {
notification: ?Notification,
): Node {
return (
<div key={title}>
<>
<h2 className={styles.addressLabel}>
{title}
</h2>
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class WalletRestoreVerifyDialog extends Component<Props> {
</CopyableAddress>
);
})}
</div>
</>
);
}

Expand Down Expand Up @@ -292,9 +292,9 @@ export default class WalletRestoreVerifyDialog extends Component<Props> {
<DialogTextBlock subclass="component-bottom">
{addressElems.map((elem, i) => {
if (i === 0) {
return <>{elem}</>;
return <span key={i}>{elem}</span>;
}
return <><br />{elem}</>;
return <span key={i}><br />{elem}</span>;
})}
</DialogTextBlock>

Expand Down
8 changes: 4 additions & 4 deletions app/components/wallet/transactions/Transaction.js
Expand Up @@ -750,11 +750,11 @@ export default class Transaction extends Component<Props, State> {
(acc, curr, idx) => {
const newElem = (
// eslint-disable-next-line react/no-array-index-key
<span key={idx}>{this.shelleyCertificateToText(curr.certificate)}</span>
<span key={idx}>
{acc.length !== 0 ? (<br />) : undefined}
{this.shelleyCertificateToText(curr.certificate)}
</span>
);
if (acc.length !== 0) {
acc.push(<br />);
}
acc.push(newElem);
return acc;
},
Expand Down
5 changes: 5 additions & 0 deletions app/i18n/locales/en-US.json
Expand Up @@ -632,12 +632,17 @@
"wallet.transaction.assuranceLevel.high": "high",
"wallet.transaction.assuranceLevel.low": "low",
"wallet.transaction.assuranceLevel.medium": "medium",
"wallet.transaction.certificate.GenesisKeyDelegation": "Genesis key delegation",
"wallet.transaction.certificate.MoveInstantaneousRewardsCert": "Manually-initiated reward payout",
"wallet.transaction.certificate.OwnerStakeDelegation": "Owner stake delegation",
"wallet.transaction.certificate.PoolRegistration": "Pool registration",
"wallet.transaction.certificate.PoolRetirement": "Pool retirement",
"wallet.transaction.certificate.PoolUpdate": "Pool update",
"wallet.transaction.certificate.StakeDelegation": "Stake delegation",
"wallet.transaction.certificate.StakeDeregistration": "Staking key deregistration",
"wallet.transaction.certificate.StakeRegistration": "Staking key registration",
"wallet.transaction.certificateLabel": "Certificate",
"wallet.transaction.certificatesLabel": "Certificates",
"wallet.transaction.confirmations": "confirmations",
"wallet.transaction.conversion.rate": "Conversion rate",
"wallet.transaction.export.dialog.exportButton.label": "Export",
Expand Down

0 comments on commit f2db231

Please sign in to comment.