Skip to content

Commit

Permalink
fix: new contract trust value.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Jul 26, 2024
1 parent f8d1a5e commit 7d82b8f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@rabby-wallet/eth-watch-keyring": "1.0.0",
"@rabby-wallet/gnosis-sdk": "1.3.6",
"@rabby-wallet/page-provider": "0.4.0",
"@rabby-wallet/rabby-api": "^0.7.24-alpha.2",
"@rabby-wallet/rabby-api": "^0.7.24-alpha.3",
"@rabby-wallet/rabby-security-engine": "2.0.4",
"@rabby-wallet/rabby-swap": "0.0.38",
"@rabby-wallet/widgets": "1.0.9",
Expand Down
16 changes: 7 additions & 9 deletions src/ui/views/ApprovalManagePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function getColumnsForContract({
</div>
);
},
width: 420,
width: 380,
},
// Contract Trust value
{
Expand Down Expand Up @@ -292,8 +292,8 @@ function getColumnsForContract({
return checkResult.keepRiskFirstReturnValue;

return (
a.$riskAboutValues.risk_exposure_usd_value -
b.$riskAboutValues.risk_exposure_usd_value
b.$riskAboutValues.risk_spend_usd_value -
a.$riskAboutValues.risk_spend_usd_value
);
},
sortOrder:
Expand All @@ -302,11 +302,11 @@ function getColumnsForContract({
if (row.type !== 'contract') return null;

const isDanger =
row.$contractRiskEvaluation.extra.clientExposureScore >=
row.$contractRiskEvaluation.extra.clientSpendScore >=
RiskNumMap.danger;
const isWarning =
!isDanger &&
row.$contractRiskEvaluation.extra.clientExposureScore >=
row.$contractRiskEvaluation.extra.clientSpendScore >=
RiskNumMap.warning;

const isRisk = isDanger || isWarning;
Expand Down Expand Up @@ -355,14 +355,12 @@ function getColumnsForContract({
'is-danger': isDanger,
})}
>
{formatUsdValue(
row.$riskAboutValues.risk_exposure_usd_value || 0
)}
{formatUsdValue(row.$riskAboutValues.risk_spend_usd_value || 0)}
</span>
</Tooltip>
);
},
width: 180,
width: 220,
},
// 24h Revoke Trends
{
Expand Down
39 changes: 22 additions & 17 deletions src/utils/approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ export type NftApprovalItem = {
};

export type ComputedRiskAboutValues = {
/** @deprecated */
risk_exposure_usd_value: number;
is_exposure_usd_value_unknown: boolean;
// is_exposure_usd_value_unknown: boolean;
risk_spend_usd_value: number;
approve_user_count: number;
revoke_user_count: number;
last_approve_at: number;
Expand All @@ -119,8 +121,8 @@ export type ComputedRiskEvaluation = {
extra: {
serverRiskLevel: ApprovalRiskLevel;

clientExposureLevel: ApprovalRiskLevel;
clientExposureScore: RiskLevelScore;
clientSpendLevel: ApprovalRiskLevel;
clientSpendScore: RiskLevelScore;

clientApprovalLevel: ApprovalRiskLevel;
clientApprovalScore: RiskLevelScore;
Expand Down Expand Up @@ -153,9 +155,10 @@ export function makeComputedRiskAboutValues(
if (contractFor === 'nft' || contractFor === 'nft-contract') {
return {
risk_exposure_usd_value: coerceFloat(spender?.exposure_nft_usd_value, 0),
is_exposure_usd_value_unknown:
spender?.exposure_nft_usd_value === null ||
typeof spender?.exposure_nft_usd_value !== 'number',
// is_exposure_usd_value_unknown:
// spender?.exposure_nft_usd_value === null ||
// typeof spender?.exposure_nft_usd_value !== 'number',
risk_spend_usd_value: coerceFloat(spender?.spend_usd_value, 0),
approve_user_count: coerceInteger(spender?.approve_user_count, 0),
revoke_user_count: coerceInteger(spender?.revoke_user_count, 0),
last_approve_at: coerceInteger(spender?.last_approve_at, 0),
Expand All @@ -164,9 +167,10 @@ export function makeComputedRiskAboutValues(

return {
risk_exposure_usd_value: coerceFloat(spender?.exposure_usd_value, 0),
is_exposure_usd_value_unknown:
spender?.exposure_usd_value === null ||
typeof spender?.exposure_usd_value !== 'number',
// is_exposure_usd_value_unknown:
// spender?.exposure_usd_value === null ||
// typeof spender?.exposure_usd_value !== 'number',
risk_spend_usd_value: coerceFloat(spender?.spend_usd_value, 0),
approve_user_count: coerceInteger(spender?.approve_user_count, 0),
revoke_user_count: coerceInteger(spender?.revoke_user_count, 0),
last_approve_at: coerceInteger(spender?.last_approve_at, 0),
Expand All @@ -183,11 +187,12 @@ export function getContractRiskEvaluation(
0
) as RiskLevelScore;

const exposureValue = coerceFloat(riskValues.risk_exposure_usd_value);
const clientExposureLevel: ApprovalRiskLevel =
exposureValue < 1e4 ? 'danger' : exposureValue < 1e5 ? 'warning' : 'safe';
const clientExposureScore = coerceInteger(
RiskNumMap[clientExposureLevel],
// const exposureValue = coerceFloat(riskValues.risk_exposure_usd_value);
const spendValue = coerceFloat(riskValues.risk_spend_usd_value);
const clientSpendLevel: ApprovalRiskLevel =
spendValue < 1e4 ? 'danger' : spendValue < 1e5 ? 'warning' : 'safe';
const clientSpendScore = coerceInteger(
RiskNumMap[clientSpendLevel],
0
) as RiskLevelScore;

Expand All @@ -212,7 +217,7 @@ export function getContractRiskEvaluation(
0
) as RiskLevelScore;

const allClientScores = [clientExposureScore, clientApprovalScore];
const allClientScores = [clientSpendScore, clientApprovalScore];

const clientMaxRiskScore = Math.max(...allClientScores) as RiskLevelScore;

Expand All @@ -229,8 +234,8 @@ export function getContractRiskEvaluation(
extra: {
serverRiskLevel,

clientExposureLevel,
clientExposureScore,
clientSpendLevel,
clientSpendScore,

clientApprovalLevel,
clientApprovalScore,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4738,10 +4738,10 @@
sinon-chrome "^3.0.1"
webextension-polyfill "0.7.0"

"@rabby-wallet/rabby-api@^0.7.24-alpha.2":
version "0.7.24-alpha.2"
resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-api/-/rabby-api-0.7.24-alpha.2.tgz#37639b912c80a754cbd867c7548b0c03714eb285"
integrity sha512-dX3jx0ScM/XlAXZ7SAWqt78aj5hV0u8lRXjkHqRpLOP44GZAk20IBSo3H/K8Bxog6feZvLRBed1zMvFm+Lg3XQ==
"@rabby-wallet/rabby-api@^0.7.24-alpha.3":
version "0.7.24-alpha.3"
resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-api/-/rabby-api-0.7.24-alpha.3.tgz#18b2096ecb6112fe7812646a3b14a37da2942cd9"
integrity sha512-P2H9qw6EOiFgkU7O34ZDLK8YJGvBuNorG5JuhWvQe74+lLIRI7oUVjMbDPz3Vc5n2dfzY4TT4ypzrAFRmW1GPA==
dependencies:
"@rabby-wallet/rabby-sign" "^0.3.3"
axios "^0.27.2"
Expand Down

0 comments on commit 7d82b8f

Please sign in to comment.