Skip to content

Commit

Permalink
Merge pull request #2 from Doge-is-Dope/ios-project
Browse files Browse the repository at this point in the history
Ios project
  • Loading branch information
Doge-is-Dope authored Nov 16, 2024
2 parents 69bc377 + 38b51c0 commit 54b9355
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 20 deletions.
4 changes: 4 additions & 0 deletions DripApp/Drip-iOS/Drip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
345D9E322CE77B8400682058 /* GetEpochInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345D9E312CE77B8400682058 /* GetEpochInfo.swift */; };
345D9E352CE8941F00682058 /* LeaderboardScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345D9E342CE8941F00682058 /* LeaderboardScreen.swift */; };
345D9E3B2CE89F2200682058 /* ProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = 345D9E3A2CE89F2200682058 /* ProgressHUD */; };
3484BAE12CE8D798007AFCE0 /* ClaimReward.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3484BAE02CE8D798007AFCE0 /* ClaimReward.swift */; };
348D93302CE248FF008E4AF0 /* ChallengeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348D932F2CE248FF008E4AF0 /* ChallengeCell.swift */; };
348D93322CE26297008E4AF0 /* QuestResultScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348D93312CE26297008E4AF0 /* QuestResultScreen.swift */; };
348D93352CE26AA4008E4AF0 /* CreateChallengeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348D93342CE26AA4008E4AF0 /* CreateChallengeScreen.swift */; };
Expand Down Expand Up @@ -128,6 +129,7 @@
345D9E2F2CE7788200682058 /* EpochInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EpochInfo.swift; sourceTree = "<group>"; };
345D9E312CE77B8400682058 /* GetEpochInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetEpochInfo.swift; sourceTree = "<group>"; };
345D9E342CE8941F00682058 /* LeaderboardScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeaderboardScreen.swift; sourceTree = "<group>"; };
3484BAE02CE8D798007AFCE0 /* ClaimReward.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClaimReward.swift; sourceTree = "<group>"; };
348D932F2CE248FF008E4AF0 /* ChallengeCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengeCell.swift; sourceTree = "<group>"; };
348D93312CE26297008E4AF0 /* QuestResultScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestResultScreen.swift; sourceTree = "<group>"; };
348D93342CE26AA4008E4AF0 /* CreateChallengeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateChallengeScreen.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -361,6 +363,7 @@
children = (
349025802CE0AAC2004ECB8F /* DripERC20Contract.swift */,
349025832CE0ABBD004ECB8F /* ApproveTransfer.swift */,
3484BAE02CE8D798007AFCE0 /* ClaimReward.swift */,
);
path = DripERC20Contract;
sourceTree = "<group>";
Expand Down Expand Up @@ -707,6 +710,7 @@
345D9E232CE596F700682058 /* GetChallngeDetail.swift in Sources */,
349025712CDF50AE004ECB8F /* GetProfile.swift in Sources */,
349025732CDF52BA004ECB8F /* DripProfileContract.swift in Sources */,
3484BAE12CE8D798007AFCE0 /* ClaimReward.swift in Sources */,
349025772CDF5454004ECB8F /* CreateProfile.swift in Sources */,
348D93322CE26297008E4AF0 /* QuestResultScreen.swift in Sources */,
);
Expand Down
11 changes: 9 additions & 2 deletions DripApp/Drip-iOS/Drip/Constants/BlockchainEnv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
import Foundation

enum BlockchainEnv {
static let chainId: String = "84532"
static let rpcURL: String = "https://sepolia.base.org"
static let polygonRPC = "https://chainlist.org/chain/2442"
static let polygonChainID = "2442"
static let mantlePRC = "https://rpc.sepolia.mantle.xyz"
static let mantleChainID = "5003"
static let basePRC = "https://sepolia.base.org"
static let baseChainId = "84532"

static let chainId: String = BlockchainEnv.baseChainId
static let rpcURL: String = BlockchainEnv.basePRC
static let nativeTokenSymbol: String = "ETH"
static let nativeTokenIcon: String = "token-eth"
}
8 changes: 4 additions & 4 deletions DripApp/Drip-iOS/Drip/Constants/DripContracts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import Foundation

enum DripContracts {
static let profile: String = "0xC5926711677BC13Ec352A6Ebfd94ADa0095C0D9B"
static let challenge: String = "0x9E3feD9c5D57F1835B57C3C19cEa7261fd78A216"
static let challengeManager: String = "0xB226f1293dDcaDc531cc2961C77F5cE2611fa8B7"
static let profile: String = "0xbaA1e7FA30539Bc29b28D0553d3c9b13bfD575CA"
static let challenge: String = "0xBef730bae27148884B7E853d0637a948F8700132"
static let challengeManager: String = "0xaE9fd9feaE497c733f53c304fAC2E67bC8148041"

static let dripERC20Token: String = "0x4152f292ef672b1b9c3eb95633bfdefccb369794"
static let dripERC20Token: String = "0x235c36243BD73d65B530a469658FeF591daA2f45"
static let dripERC20TokenSymbol: String = "DRP"
static let dripERC20TokenIcon: String = "drip-logo-full"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import SwiftUI
import BigInt
import ProgressHUD

struct ChallengePoolScreen: View {
var onLogOut: (() -> Void)?
Expand Down Expand Up @@ -163,13 +164,18 @@ struct ChallengePoolScreen: View {
viewModel.fetchChallenges()
viewModel.fetchEpochInfo()
}
.onChange(of: viewModel.isClaimed) {
ProgressHUD.dismiss()
viewModel.isClaimed = false
}
}

private func onCardButtonTap() {
if selectedPoolIndex == 0 {
isPresentingLeaderBoardScreen = true
} else {
// claim
ProgressHUD.animate("Almost there 🤜🤛")
viewModel.claim()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import BigInt
final class ChallengePoolViewModel: ObservableObject {
@Published var challenges: [DripChallenge] = []
@Published var epochInfo: DripEpochInfo?
@Published var isClaimed: Bool = false

let rpcService: RPCService

private lazy var profileContract = DripProfileContract(rpcService: rpcService, contractAddress: DripContracts.profile)
private lazy var challengeManagerContract = ChallengeManagerContract(rpcService: rpcService, contractAddress: DripContracts.challengeManager)
private lazy var erc20TokenContract = DripERC20Contract(rpcService: rpcService, contractAddress: DripContracts.dripERC20Token)

init(rpcService: RPCService) {
self.rpcService = rpcService
Expand Down Expand Up @@ -46,4 +48,14 @@ final class ChallengePoolViewModel: ObservableObject {
}
}
}

func claim() {
Task {
await erc20TokenContract.claim()
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.isClaimed = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ struct PoolInfoCard: View {
}

private var participantsCount: String {
epochInfo?.displayedParticipants ?? "-"
if isActive { return "10" }
return epochInfo?.displayedParticipants ?? "-"
}

private var daysRemaining: String {
let days = epochInfo?.daysRemaining() ?? 0
if days >= 0 {
return String(days)
private var timeRemaining: String {
if isActive {
let hours = epochInfo?.hoursRemaining() ?? 0
return String(hours)
} else {
return "-"
}
}
private var timeUnit: String {
isActive ? "Hours Remaining" : "Days Remaining"
}

private var totalStakedAmount: String {
epochInfo?.totalStakedAmount ?? "-"
Expand Down Expand Up @@ -75,9 +79,9 @@ struct PoolInfoCard: View {
.padding(.all, 16)
.background(bgColor)
HStack {
PoolInfoChip(mainText: .constant(daysRemaining), subText: .constant("Days Remaining"))
PoolInfoChip(mainText: .constant(timeRemaining), subText: .constant(timeUnit))
PoolInfoChip(mainText: .constant(participantsCount), subText: .constant("Participants"))
PoolInfoChip(mainText: .constant(totalStakedAmount), subText: .constant("USDC Staked"))
PoolInfoChip(mainText: .constant(totalStakedAmount), subText: .constant("\(DripContracts.dripERC20TokenSymbol) Staked"))
}
.padding(.all, 16)
.background(.white)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import SwiftUI
import ProgressHUD

struct CreateChallengeScreen: View {
@State private var name: String = ""
@State private var amount: String = ""
@State private var days: String = ""
@State private var desc: String = ""
@State private var name: String = "ETHGlobal Bangkok"
@State private var amount: String = "20"
@State private var days: String = "5"
@State private var desc: String = "Demo in ETHGlobal Bangkok"
@Environment(\.dismiss) private var dismiss

@StateObject private var viewModel: CreateChallengeViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
// Created by Shane Chi

import SwiftUI
import ProgressHUD

struct SetProfileScreen: View {

var onSignIn: (() -> Void)?

@StateObject private var viewModel: SetProfileViewModel
@State private var username: String = ""
@State private var username: String = "YuHsuan Chi"

init(viewModel: SetProfileViewModel, onSignIn: (() -> Void)? = nil
) {
Expand Down Expand Up @@ -58,6 +59,7 @@ struct SetProfileScreen: View {
}
Spacer()
ActionButton(title: "Done") {
ProgressHUD.animate("Almost there 🤜🤛")
viewModel.setProfile(userHandle: username)
}
}
Expand All @@ -68,6 +70,8 @@ struct SetProfileScreen: View {
.onChange(of: viewModel.isProfileCreated) {
guard viewModel.isProfileCreated else { return }
onSignIn?()
viewModel.isProfileCreated = false
ProgressHUD.dismiss()
}
}
}
2 changes: 1 addition & 1 deletion DripApp/Drip-iOS/Drip/Scenes/SignIn/SignInScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct SignInScreen: View {
var onSignIn: (() -> Void)?

@StateObject private var viewModel: SignInViewModel
@State private var emailText: String = ""
@State private var emailText: String = "[email protected]"

init(viewModel: SignInViewModel, onSignIn: (() -> Void)? = nil) {
_viewModel = StateObject(wrappedValue: viewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ extension DripEpochInfo {
return daysDifference
}

func hoursRemaining() -> Int {
let now = Date()
let end = endTimestamp.description
let targetDate = Date(timeIntervalSince1970: Double(end) ?? 0)

let calendar = Calendar.current
guard let hoursDifference = calendar.dateComponents([.hour], from: now, to: targetDate).hour else {
return 0
}

return hoursDifference
}

var totalStakedAmount: String {
totalDeposits.description.convertBigIntToDecimalFormat(
decimals: 18,
Expand Down
40 changes: 40 additions & 0 deletions DripApp/Drip-iOS/Drip/Services/DripERC20Contract/ClaimReward.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// ClaimReward.swift
// Drip
//
// Created by Shane Chi on 2024/11/16.
//

import Foundation
import BigInt
import web3

struct ClaimReward: ABIFunction {
public var from: web3.EthereumAddress?

public static let name = "setBalance"
public let gasPrice: BigUInt? = nil
public let gasLimit: BigUInt? = nil
public let contract: EthereumAddress

// function params
private let ownerAddress: EthereumAddress
private let amount: BigUInt

init(
from: web3.EthereumAddress?,
contract: EthereumAddress,
ownerAddress: String,
amount: BigUInt
) {
self.from = from
self.contract = contract
self.ownerAddress = EthereumAddress(stringLiteral: ownerAddress)
self.amount = amount
}

func encode(to encoder: ABIFunctionEncoder) throws {
try encoder.encode(ownerAddress)
try encoder.encode(amount)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ final class DripERC20Contract {
guard let bal else { return nil }
return bal.description.convertBigIntToDecimalFormat(decimals: 18, decimalPlaces: 6)
}

func claim() async {
guard let bal = try? await erc20.balanceOf(tokenContract: contractAddress, address: rpcService.rawAddress) else {
return
}
let newBalance: BigUInt = bal.advanced(by: BigInt(BigUInt(100).multiplied(by: BigUInt(10).power(18))))
let claimRewardFunction = ClaimReward(
from: rpcService.rawAddress,
contract: contractAddress,
ownerAddress: rpcService.accountAddress,
amount: newBalance
)
let result = await rpcService.sendTransaction(claimRewardFunction)
print(result)
}
}

0 comments on commit 54b9355

Please sign in to comment.