@@ -17,18 +17,50 @@ pub enum ClaimType {
1717#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord ) ]
1818pub struct Claim {
1919 pub claim_type : ClaimType ,
20- pub amount : u128 , // For NEAR and FTs. Ignored for NFTs
20+ pub amount : NearToken , // For NEAR and FTs. Ignored for NFTs
2121 pub tipper : AccountId ,
2222 pub timestamp : u64 ,
2323 pub expires_at : u64 ,
2424 pub claimed : bool ,
2525}
2626
27+ #[ near( serializers=[ borsh, json] ) ]
28+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord ) ]
29+ pub struct ClaimExternal {
30+ pub id : ClaimId ,
31+ pub claim_type : String ,
32+ pub amount : U128 , // For NEAR and FTs. Ignored for NFTs
33+ pub tipper : AccountId ,
34+ pub timestamp : u64 ,
35+ pub expires_at : u64 ,
36+ pub claimed : bool ,
37+ }
38+
39+ pub ( crate ) fn format_claim ( claim_id : & ClaimId , claim : & Claim ) -> ClaimExternal {
40+ let claim_type = match & claim. claim_type {
41+ ClaimType :: Near => "Near" . to_string ( ) ,
42+ ClaimType :: FungibleToken { contract_id } => format ! ( "FT({})" , contract_id) ,
43+ ClaimType :: NonFungibleToken {
44+ contract_id,
45+ token_id,
46+ } => format ! ( "NFT({}, {})" , contract_id, token_id) ,
47+ } ;
48+ ClaimExternal {
49+ id : claim_id. clone ( ) ,
50+ claim_type,
51+ amount : claim. amount . as_yoctonear ( ) . into ( ) ,
52+ tipper : claim. tipper . clone ( ) ,
53+ timestamp : claim. timestamp ,
54+ expires_at : claim. expires_at ,
55+ claimed : claim. claimed ,
56+ }
57+ }
58+
2759impl Claim {
2860 pub fn new_near ( tipper : AccountId , amount : u128 ) -> Self {
2961 Self {
3062 claim_type : ClaimType :: Near ,
31- amount,
63+ amount : NearToken :: from_yoctonear ( amount ) ,
3264 tipper,
3365 timestamp : env:: block_timestamp ( ) ,
3466 expires_at : env:: block_timestamp ( ) + crate :: CLAIM_EXPIRATION_PERIOD ,
@@ -39,7 +71,7 @@ impl Claim {
3971 pub fn new_ft ( tipper : AccountId , contract_id : AccountId , amount : u128 ) -> Self {
4072 Self {
4173 claim_type : ClaimType :: FungibleToken { contract_id } ,
42- amount,
74+ amount : NearToken :: from_yoctonear ( amount ) ,
4375 tipper,
4476 timestamp : env:: block_timestamp ( ) ,
4577 expires_at : env:: block_timestamp ( ) + crate :: CLAIM_EXPIRATION_PERIOD ,
@@ -53,7 +85,7 @@ impl Claim {
5385 contract_id,
5486 token_id,
5587 } ,
56- amount : 0 , // Not used for NFTs
88+ amount : NearToken :: from_yoctonear ( 0 ) , // Not used for NFTs
5789 tipper,
5890 timestamp : env:: block_timestamp ( ) ,
5991 expires_at : env:: block_timestamp ( ) + crate :: CLAIM_EXPIRATION_PERIOD ,
@@ -66,7 +98,7 @@ impl Claim {
6698 }
6799
68100 pub fn amount ( & self ) -> u128 {
69- self . amount
101+ self . amount . as_yoctonear ( )
70102 }
71103
72104 pub fn tipper ( & self ) -> & AccountId {
0 commit comments